Ejemplo n.º 1
0
        public FormSelectPropertyEnum(DocProject project, DocPropertyEnumeration selection)
            : this()
        {
            this.m_project = project;

            SortedList<string, DocPropertyEnumeration> list = new SortedList<string, DocPropertyEnumeration>();
            foreach(DocSection section in project.Sections)
            {
                foreach(DocSchema schema in section.Schemas)
                {
                    foreach(DocPropertyEnumeration enumeration in schema.PropertyEnums)
                    {
                        list.Add(enumeration.Name, enumeration);
                    }
                }
            }

            foreach (string s in list.Keys)
            {
                DocPropertyEnumeration enumeration = list[s];
                ListViewItem lvi = new ListViewItem();
                lvi.Tag = enumeration;
                lvi.Text = enumeration.Name;
                lvi.ImageIndex = 0;
                this.listView.Items.Add(lvi);

                if (selection == enumeration)
                {
                    lvi.Selected = true;
                }
            }
        }
Ejemplo n.º 2
0
        public FormSelectPropertyEnum(DocProject project, DocPropertyEnumeration selection) : this()
        {
            this.m_project = project;

            SortedList <string, DocPropertyEnumeration> list = new SortedList <string, DocPropertyEnumeration>();

            foreach (DocPropertyEnumeration enumeration in project.PropertyEnumerations)
            {
                list.Add(enumeration.Name, enumeration);
            }

            foreach (string s in list.Keys)
            {
                DocPropertyEnumeration enumeration = list[s];
                ListViewItem           lvi         = new ListViewItem();
                lvi.Tag        = enumeration;
                lvi.Text       = enumeration.Name;
                lvi.ImageIndex = 0;
                this.listView.Items.Add(lvi);

                if (selection == enumeration)
                {
                    lvi.Selected = true;
                }
            }
        }
Ejemplo 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)
                {
                    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);
                    }
                }
            }
        }
        public FormSelectPropertyEnum(DocProject project, DocPropertyEnumeration selection) : this()
        {
            this.m_project = project;

            foreach(DocSection section in project.Sections)
            {
                foreach(DocSchema schema in section.Schemas)
                {
                    foreach(DocPropertyEnumeration enumeration in schema.PropertyEnums)
                    {
                        ListViewItem lvi = new ListViewItem();
                        lvi.Tag = enumeration;
                        lvi.Text = enumeration.Name;
                        this.listView.Items.Add(lvi);

                        if (selection == enumeration)
                        {
                            lvi.Selected = true;
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public FormSelectPropertyEnum(DocProject project, DocPropertyEnumeration selection) : this()
        {
            this.m_project = project;

            foreach (DocSection section in project.Sections)
            {
                foreach (DocSchema schema in section.Schemas)
                {
                    foreach (DocPropertyEnumeration enumeration in schema.PropertyEnums)
                    {
                        ListViewItem lvi = new ListViewItem();
                        lvi.Tag  = enumeration;
                        lvi.Text = enumeration.Name;
                        this.listView.Items.Add(lvi);

                        if (selection == enumeration)
                        {
                            lvi.Selected = true;
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
        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);
            }
        }
Ejemplo n.º 7
0
        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);
            }
        }
Ejemplo n.º 8
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;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 9
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);
                        }
                    }
                }
            }
        }
Ejemplo n.º 10
0
        public static void Upload(DocProject docProject, BackgroundWorker worker, string baseurl, string username, string password, string parentid, DocModelView[] docViews)
        {
            string sessionid = Connect(docProject, worker, baseurl, username, password);

#if false
            if (docViews != null && docViews.Length > 0)
            {
                foreach (DocModelView docView in docViews)//docProject.ModelViews)
                {
                    // hack: only bridge view for now
                    if (docView.Name.Contains("Bridge"))
                    {
                        string codename = docView.Name;
                        if (!String.IsNullOrEmpty(docView.Code))
                        {
                            codename = docView.Code;
                        }

                        IfdBase ifdView = CreateConcept(baseurl, sessionid, docView, codename, docView.Name, IfdConceptTypeEnum.BAG);
                        //CreateRelationship(baseurl, sessionid, parentid, ifdView.guid, "COLLECTS"); // no top-level item for now

                        foreach (DocConceptRoot docRoot in docView.ConceptRoots)
                        {
                            if (docRoot.Name != null)
                            {
                                System.Diagnostics.Debug.WriteLine(docRoot.ToString());

                                IfdBase ifdRoot = CreateConcept(baseurl, sessionid, docRoot, docRoot.ApplicableEntity.Name, docRoot.Name, IfdConceptTypeEnum.SUBJECT);
                                CreateRelationship(baseurl, sessionid, ifdView.guid, ifdRoot.guid, IfdRelationshipTypeEnum.COLLECTS);

                                foreach (DocTemplateUsage docConc in docRoot.Concepts)
                                {
                                    UploadTemplateUsage(docProject, baseurl, sessionid, ifdRoot.guid, docConc);
                                }
                            }
                        }
                    }
                }
            }
            else
#endif
            {
                // build list of types referenced by property sets
                Dictionary <string, IfdBase> mapEntities = new Dictionary <string, IfdBase>();


                // core schema
                foreach (DocSection docSection in docProject.Sections)
                {
                    foreach (DocSchema docSchema in docSection.Schemas)
                    {
                        // only export objects that have associated property sets
                        foreach (DocPropertySet docPset in docSchema.PropertySets)
                        {
                            IfdBase ifdPset = CreateConcept(baseurl, sessionid, docPset, docPset.Name, docPset.Name, docPset.PropertySetType.ToString(), IfdConceptTypeEnum.BAG);
                            foreach (DocProperty docProp in docPset.Properties)
                            {
                                IfdBase ifdProp = CreateConcept(baseurl, sessionid, docProp, docProp.Name, docProp.Name, docProp.PropertyType.ToString(), IfdConceptTypeEnum.PROPERTY);
                                if (ifdProp != null)
                                {
                                    CreateRelationship(baseurl, sessionid, ifdPset.guid, ifdProp.guid, IfdRelationshipTypeEnum.COLLECTS);

                                    string paramval = docProp.PrimaryDataType;
                                    if (!String.IsNullOrEmpty(paramval))
                                    {
                                        DocDefinition docDef = docProject.GetDefinition(paramval);
                                        if (docDef != null)
                                        {
                                            // get the measure type
                                            IfdBase ifdType = SearchConcept(baseurl, sessionid, docDef.Name, IfdConceptTypeEnum.MEASURE);
                                            if (ifdType == null)
                                            {
                                                // create concept
                                                ifdType = CreateConcept(baseurl, sessionid, docDef, docDef.Name, docDef.Name, null, IfdConceptTypeEnum.MEASURE);

                                                // for enums, get enumerated type
                                                if (docProp.PropertyType == DocPropertyTemplateTypeEnum.P_ENUMERATEDVALUE)
                                                {
                                                    DocSchema docPropSchema            = null;
                                                    DocPropertyEnumeration docPropEnum = docProject.FindPropertyEnumeration(docProp.SecondaryDataType, out docPropSchema);
                                                    if (docPropEnum != null)
                                                    {
                                                        foreach (DocPropertyConstant docPropConst in docPropEnum.Constants)
                                                        {
                                                            IfdBase ifdConst = CreateConcept(baseurl, sessionid, docPropConst, docPropConst.Name, docPropConst.Name, null, IfdConceptTypeEnum.VALUE);
                                                            CreateRelationship(baseurl, sessionid, ifdType.guid, ifdConst.guid, IfdRelationshipTypeEnum.ASSIGNS_VALUES);
                                                        }
                                                    }
                                                }
                                            }
                                            CreateRelationship(baseurl, sessionid, ifdProp.guid, ifdType.guid, IfdRelationshipTypeEnum.ASSIGNS_MEASURES); // ??? fails for Pset_BuildingUse.NarrativeText / IfcText
                                        }
                                    }
                                }
                            }

                            // now link the property set to applicable type
                            DocEntity[] docEntities = docPset.GetApplicableTypeDefinitions(docProject);
                            if (docEntities != null && docEntities.Length > 0)
                            {
                                // only the first one matters
                                DocEntity docEnt = docEntities[0];
                                IfdBase   ifdEnt = null;
                                if (!mapEntities.TryGetValue(docEnt.Name, out ifdEnt))
                                {
                                    ifdEnt = CreateConcept(baseurl, sessionid, docEnt, docEnt.Name, docEnt.Name, null, IfdConceptTypeEnum.SUBJECT);
                                    mapEntities.Add(docEnt.Name, ifdEnt);

                                    // subtypes (predefined type)
                                    foreach (DocAttribute docAttr in docEnt.Attributes)
                                    {
                                        if (docAttr.Name.Equals("PredefinedType"))
                                        {
                                            DocEnumeration docEnum = docProject.GetDefinition(docAttr.DefinedType) as DocEnumeration;
                                            if (docEnum != null)
                                            {
                                                foreach (DocConstant docConst in docEnum.Constants)
                                                {
                                                    IfdBase ifdConst = CreateConcept(baseurl, sessionid, docConst, docConst.Name, docConst.Name, null, IfdConceptTypeEnum.SUBJECT);
                                                    CreateRelationship(baseurl, sessionid, ifdEnt.guid, ifdConst.guid, IfdRelationshipTypeEnum.SPECIALIZES);
                                                }
                                            }
                                        }
                                    }
                                }
                                CreateRelationship(baseurl, sessionid, ifdEnt.guid, ifdPset.guid, IfdRelationshipTypeEnum.ASSIGNS_COLLECTIONS); //!!! Fails with Forbidden!!! why???
                                // http://test.bsdd.buildingsmart.org/api/4.0/IfdRelationship/validrelations/SUBJECT/BAG indicates
                                // <ifdRelationshipTypeEnums>
                                //   <IfdRelationshipType xmlns="http://peregrine.catenda.no/objects">ASSIGNS_COLLECTIONS</IfdRelationshipType>
                                // </ifdRelationshipTypeEnums>
                            }
                        }

                        foreach (DocQuantitySet docPset in docSchema.QuantitySets)
                        {
                            IfdBase ifdPset = CreateConcept(baseurl, sessionid, docPset, docPset.Name, docPset.Name, "QTO_OCCURRENCEDRIVEN", IfdConceptTypeEnum.BAG);
                            foreach (DocQuantity docProp in docPset.Quantities)
                            {
                                IfdBase ifdProp = CreateConcept(baseurl, sessionid, docProp, docProp.Name, docProp.Name, docProp.QuantityType.ToString(), IfdConceptTypeEnum.PROPERTY);
                                if (ifdProp != null)
                                {
                                    CreateRelationship(baseurl, sessionid, ifdPset.guid, ifdProp.guid, IfdRelationshipTypeEnum.COLLECTS);

                                    string propclass = "IfcQuantityCount";
                                    switch (docProp.QuantityType)
                                    {
                                    case DocQuantityTemplateTypeEnum.Q_AREA:
                                        propclass = "IfcQuantityArea";
                                        break;

                                    case DocQuantityTemplateTypeEnum.Q_COUNT:
                                        propclass = "IfcQuantityCount";
                                        break;

                                    case DocQuantityTemplateTypeEnum.Q_LENGTH:
                                        propclass = "IfcQuantityLength";
                                        break;

                                    case DocQuantityTemplateTypeEnum.Q_TIME:
                                        propclass = "IfcQuantityTime";
                                        break;

                                    case DocQuantityTemplateTypeEnum.Q_VOLUME:
                                        propclass = "IfcQuantityVolume";
                                        break;

                                    case DocQuantityTemplateTypeEnum.Q_WEIGHT:
                                        propclass = "IfcQuantityWeight";
                                        break;
                                    }

                                    string paramval = propclass;
                                    if (!String.IsNullOrEmpty(paramval))
                                    {
                                        DocDefinition docDef = docProject.GetDefinition(paramval);
                                        if (docDef != null)
                                        {
                                            // get the measure type
                                            IfdBase ifdType = SearchConcept(baseurl, sessionid, docDef.Name, IfdConceptTypeEnum.MEASURE);
                                            if (ifdType == null)
                                            {
                                                // create concept
                                                ifdType = CreateConcept(baseurl, sessionid, docDef, docDef.Name, docDef.Name, null, IfdConceptTypeEnum.MEASURE);
                                            }
                                            CreateRelationship(baseurl, sessionid, ifdProp.guid, ifdType.guid, IfdRelationshipTypeEnum.ASSIGNS_MEASURES); // ??? fails for Pset_BuildingUse.NarrativeText / IfcText
                                        }
                                    }
                                }
                            }

                            // now link the property set to applicable type
                            DocEntity[] docEntities = docPset.GetApplicableTypeDefinitions(docProject);
                            if (docEntities != null && docEntities.Length > 0)
                            {
                                // only the first one matters
                                DocEntity docEnt = docEntities[0];
                                IfdBase   ifdEnt = null;
                                if (mapEntities.TryGetValue(docEnt.Name, out ifdEnt))
                                {
                                    CreateRelationship(baseurl, sessionid, ifdEnt.guid, ifdPset.guid, IfdRelationshipTypeEnum.ASSIGNS_COLLECTIONS);
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 11
0
        private void toolStripMenuItemInsertPropertyEnumeration_Click(object sender, EventArgs e)
        {
            TreeNode tnParent = this.treeView.SelectedNode;

            TreeNode tn = tnParent;
            if (tn.Parent.Tag is DocSchema)
            {
                tn = tn.Parent;
            }

            if (tn.Tag is DocSchema)
            {
                DocSchema docSchema = (DocSchema)tn.Tag;
                DocPropertyEnumeration docType = new DocPropertyEnumeration();
                docSchema.PropertyEnums.Add(docType);
                this.treeView.SelectedNode = this.LoadNode(tn.Nodes[4], docType, null, true);
                toolStripMenuItemEditRename_Click(this, e);
            }
        }
Ejemplo n.º 12
0
        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();
        }