Esempio n. 1
0
        public FieldBuilder CreateField(SchemaBuilder schemaBuilder,
                                        PropertyInfo propertyInfo)
        {
            FieldBuilder fieldBuilder;

            var genericKeyType   = propertyInfo.PropertyType.GetGenericArguments()[0];
            var genericValueType = propertyInfo.PropertyType.GetGenericArguments()[1];

            if (genericValueType.GetInterface("IRevitEntity") != null)
            {
                fieldBuilder =
                    schemaBuilder.AddMapField(propertyInfo.Name,
                                              genericKeyType, typeof(Entity));

                AttributeExtractor <SchemaAttribute> schemaAttributeExtractor =
                    new AttributeExtractor <SchemaAttribute>();
                var subSchemaAttribute =
                    schemaAttributeExtractor
                    .GetAttribute(genericValueType);
                fieldBuilder
                .SetSubSchemaGUID(subSchemaAttribute.GUID);
            }
            else
            {
                fieldBuilder =
                    schemaBuilder.AddMapField(propertyInfo.Name,
                                              genericKeyType, genericValueType);
            }

            var needSubschemaId = fieldBuilder.NeedsSubSchemaGUID();

            return(fieldBuilder);
        }
Esempio n. 2
0
        /// <summary>
        /// Создает схему
        /// </summary>
        /// <returns></returns>
        public Schema CreateSchema()
        {
            Guid schemaGuid = new Guid(GuidValue);

            SchemaBuilder schemaBuilder = new SchemaBuilder(schemaGuid);

            // set read access
            schemaBuilder.SetReadAccessLevel(AccessLevel.Public);

            // set write access
            schemaBuilder.SetWriteAccessLevel(AccessLevel.Public);

            // set schema name
            schemaBuilder.SetSchemaName(SchemaName);

            // create a field to store the bool value
            FieldBuilder fbString = schemaBuilder.AddMapField("Dict_String", typeof(int), typeof(string));
            FieldBuilder fbInt    = schemaBuilder.AddMapField("Dict_Int", typeof(int), typeof(int));
            FieldBuilder fbDouble = schemaBuilder.AddMapField("Dict_Double", typeof(int), typeof(double));

            fbDouble.SetUnitType(UnitType.UT_Length);
            FieldBuilder fbElemId = schemaBuilder.AddMapField("Dict_ElemId", typeof(int), typeof(ElementId));
            FieldBuilder fbXYZ    = schemaBuilder.AddMapField("Dict_XYZ", typeof(int), typeof(XYZ));

            fbXYZ.SetUnitType(UnitType.UT_Length);

            // register the schema
            Schema schema = schemaBuilder.Finish();

            return(schema);
        }
Esempio n. 3
0
        public static Schema CreateSchema()
        {
            Guid schemaGuid = new Guid("ce6a412e-1e20-4ac3-a081-0a6bde126466");

            SchemaBuilder schemaBuilder = new SchemaBuilder(schemaGuid);

            // set read access
            schemaBuilder.SetReadAccessLevel(AccessLevel.Public);

            // set write access
            schemaBuilder.SetWriteAccessLevel(AccessLevel.Public);

            // set schema name
            schemaBuilder.SetSchemaName("AgSchema");

            // set documentation
            schemaBuilder.SetDocumentation(
                "Хранение ElementId элементов узлов из принципиальной схемы внутри экземпляров семейств модели");

            // create a field to store the bool value
            FieldBuilder elemIdField     = schemaBuilder.AddMapField("DictElemId", typeof(Int32), typeof(ElementId));
            FieldBuilder elemStringField = schemaBuilder.AddMapField("DictString", typeof(Int32), typeof(string));
            FieldBuilder elemIntField    = schemaBuilder.AddMapField("DictInt", typeof(Int32), typeof(Int32));

            // register the schema
            Schema schema = schemaBuilder.Finish();

            return(schema);
        }
Esempio n. 4
0
        /// <summary>
        ///     Creates an IDictionary type field builder by field name.
        /// </summary>
        /// <typeparam name="K"></typeparam>
        /// <typeparam name="V"></typeparam>
        /// <param name="schemaBuilder"></param>
        /// <param name="fieldName"></param>
        /// <param name="unitType"></param>
        /// <param name="dcrp"></param>
        /// <returns></returns>
        public static void AddDictField <K, V>(this SchemaBuilder schemaBuilder, string fieldName, UnitType unitType, string dcrp = null)
        {
            if (schemaBuilder is null)
            {
                throw new ArgumentNullException(nameof(schemaBuilder));
            }

            if (fieldName is null)
            {
                throw new ArgumentNullException(nameof(fieldName));
            }

            if (!typeof(K).IsPrimitive)
            {
                throw new NotSupportedException(nameof(K));
            }

            if (!typeof(V).IsPrimitive)
            {
                throw new NotSupportedException(nameof(V));
            }

            var result = schemaBuilder.AddMapField(fieldName, typeof(K), typeof(V));

            result.SetUnitType(unitType);

            result.SetDocumentation(dcrp);
        }
Esempio n. 5
0
        /// <summary>
        ///     Creates an dictionary type field builder by field name.
        /// </summary>
        /// <typeparam name="K"></typeparam>
        /// <typeparam name="V"></typeparam>
        /// <param name="schemaBuilder"></param>
        /// <param name="fieldName"></param>
        /// <param name="unitType"></param>
        /// <param name="desc"></param>
        /// <returns></returns>
        public static FieldBuilder CreateDictField <K, V>(this SchemaBuilder schemaBuilder, string fieldName,
                                                          UnitType unitType, string desc = null)
        {
            if (schemaBuilder is null)
            {
                throw new ArgumentNullException(nameof(schemaBuilder));
            }

            if (fieldName is null)
            {
                throw new ArgumentNullException(nameof(fieldName));
            }

            if (desc is null)
            {
                throw new ArgumentNullException(nameof(desc));
            }

            var result = schemaBuilder.AddMapField(fieldName, typeof(K), typeof(V));

            result.SetUnitType(unitType);
            result.SetDocumentation(desc);

            return(result);
        }
Esempio n. 6
0
        public static Schema CreateSchema()
        {
            Schema schema    = null;
            Schema subSchema = null;

            try
            {
                SchemaBuilder subSchemaBuilder = new SchemaBuilder(subSchemaId);
                subSchemaBuilder.SetSchemaName("ElementIds");
                subSchemaBuilder.AddArrayField(s_ElementIds, typeof(ElementId));
                subSchema = subSchemaBuilder.Finish();

                SchemaBuilder schemaBuilder = new SchemaBuilder(schemaId);
                schemaBuilder.SetSchemaName("ColorEditorSetting");
                schemaBuilder.AddSimpleField(s_BCFPath, typeof(string));
                var mapField = schemaBuilder.AddMapField(s_ColoredElementIds, typeof(string), typeof(Entity));
                mapField.SetSubSchemaGUID(subSchemaId);
                schema = schemaBuilder.Finish();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to create schema for Color Scheme Editor.\n" + ex.Message, "Create Schema", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(schema);
        }
Esempio n. 7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="guid"></param>
        /// <param name="extraDetails">extraDetails[0] holds the schema's name,
        /// with other array elements naming the fields</param>
        /// <returns></returns>
        internal static Schema GetSchema(Guid guid, params string[] extraDetails)
        {
            // 1. Try to look up the schema
            Schema schema = Schema.Lookup(guid);

            if (schema == null &&
                extraDetails.Length > 2)
            {
                // 2. Create and name a new schema
                SchemaBuilder schemaBuilder = new SchemaBuilder(guid);
                schemaBuilder.SetSchemaName(extraDetails[0]);

                // 3. Set read/write access for the schema
                schemaBuilder.SetReadAccessLevel(AccessLevel.Public);
                schemaBuilder.SetWriteAccessLevel(AccessLevel.Vendor);
                schemaBuilder.SetVendorId(VENDOR_ID);

                // 4. Define one or more fields of data
                for (int i = 1; i < extraDetails.Length; ++i)
                {
                    schemaBuilder.AddMapField(
                        extraDetails[i], typeof(string), typeof(string));
                }
                schema = schemaBuilder.Finish();
            }
            return(schema);
        }
Esempio n. 8
0
        public Schema CreateSchema(Guid schemaGuid)
        {
            Schema schema = Schema.Lookup(schemaGuid);

            if (schema == null)
            {
                SchemaBuilder schemaBuilder = new SchemaBuilder(schemaGuid);
                schemaBuilder.SetReadAccessLevel(AccessLevel.Public);
                schemaBuilder.SetWriteAccessLevel(AccessLevel.Public);
                //schemaBuilder.SetWriteAccessLevel(AccessLevel.Vendor);
                //schemaBuilder.SetVendorId("CBIM");

                FieldBuilder fieldBuilder = schemaBuilder.AddSimpleField("XYZ", typeof(XYZ));
                fieldBuilder.SetUnitType(UnitType.UT_Length);
                fieldBuilder.SetDocumentation("I'm XYZ");

                FieldBuilder fieldBuilder1 = schemaBuilder.AddSimpleField("Double", typeof(double));
                fieldBuilder1.SetUnitType(UnitType.UT_Length);
                fieldBuilder1.SetDocumentation("I'm Double");

                //Ilist<string>
                FieldBuilder fieldBuilder2 = schemaBuilder.AddArrayField("List", typeof(string));
                //fieldBuilder2.SetUnitType(UnitType.UT_Length);
                fieldBuilder2.SetDocumentation("I'm Ilist<string>");

                //IDictinary<string,int>
                FieldBuilder fieldBuilder3 = schemaBuilder.AddMapField("Dictionary", typeof(string), typeof(int));
                //fieldBuilder3.SetUnitType(UnitType.UT_Length);
                fieldBuilder3.SetDocumentation("I'm IDictinary<string,int>");

                //SubSchema
                //Guid guid = new Guid("f9b00633-6aa9-47a6-acea-7f74407b9ea5");
                //Schema subSchema = Schema.Lookup(guid);
                //if (subSchema == null)
                //{
                //    SchemaBuilder subSchemaBuilder = new SchemaBuilder(guid);
                //    subSchemaBuilder.SetReadAccessLevel(AccessLevel.Public);
                //    subSchemaBuilder.SetWriteAccessLevel(AccessLevel.Public);

                //    FieldBuilder sub = subSchemaBuilder.AddSimpleField("subInt", typeof(int));
                //    sub.SetDocumentation("I'm Int");

                //    subSchemaBuilder.SetSchemaName("SubSchema");
                //    subSchema = subSchemaBuilder.Finish();
                //}
                //Entity subEntity = new Entity(subSchema);
                //subEntity.Set<int>(subSchema.GetField("subInt"), 11);

                //FieldBuilder fieldBuilder4 = schemaBuilder.AddSimpleField("SubEntity", typeof(Entity));
                //fieldBuilder4.SetDocumentation("I'm SubSchema");


                schemaBuilder.SetSchemaName("SchemaName");
                schema = schemaBuilder.Finish();
            }

            return(schema);
        }
Esempio n. 9
0
        public static Schema createSchema_FurnLocations()
        {
            Guid          myGUID          = new Guid(myConstantStringSchema_FurnLocations);
            SchemaBuilder mySchemaBuilder = new SchemaBuilder(myGUID);

            mySchemaBuilder.SetSchemaName("FurnLocations");

            FieldBuilder mapField_Child = mySchemaBuilder.AddMapField("FurnLocations", typeof(ElementId), typeof(XYZ));

            mapField_Child.SetUnitType(UnitType.UT_Length);

            FieldBuilder mapField_Child_Angle = mySchemaBuilder.AddMapField("FurnLocations_Angle", typeof(ElementId), typeof(double));

            mapField_Child_Angle.SetUnitType(UnitType.UT_Length);
            //IList<int> list = new List<int>() { 111, 222, 333 };

            return(mySchemaBuilder.Finish());
        }
Esempio n. 10
0
        /// <summary>
        /// Creates Speckle Schema.
        /// </summary>
        /// <returns></returns>
        public static Schema CreateSchema()
        {
            var schemaGuid    = new Guid(Properties.Resources.SchemaId);
            var schemaBuilder = new SchemaBuilder(schemaGuid);

            schemaBuilder.SetReadAccessLevel(AccessLevel.Public);
            schemaBuilder.SetWriteAccessLevel(AccessLevel.Application);

            // (Konrad) These values are set in addin manifest.
            schemaBuilder.SetApplicationGUID(new Guid("0a03f52e-0ee0-4c19-82c4-8181626ec816"));
            schemaBuilder.SetVendorId("Speckle");

            schemaBuilder.SetSchemaName(Properties.Resources.SchemaName);
            schemaBuilder.SetDocumentation("Speckle schema.");
            schemaBuilder.AddMapField("senders", typeof(string), typeof(string));
            schemaBuilder.AddMapField("receivers", typeof(string), typeof(string));
            var schema = schemaBuilder.Finish();

            return(schema);
        }
Esempio n. 11
0
        public static Schema createSchema_FurnLocations_Index()
        {
            SchemaBuilder mySchemaBuilder = new SchemaBuilder(new Guid(myConstantStringSchema_FurnLocations_Index));

            mySchemaBuilder.SetSchemaName("FurnLocations_Index");
            FieldBuilder mapField_Parent = mySchemaBuilder.AddMapField("FurnLocations_Index", typeof(string), typeof(Entity));

            mapField_Parent.SetSubSchemaGUID(new Guid(myConstantStringSchema_FurnLocations));

            return(mySchemaBuilder.Finish());
        }
Esempio n. 12
0
        /// <summary>
        ///     Sets an entity.
        /// </summary>
        /// <param name="elm"></param>
        /// <param name="schemaName"></param>
        /// <param name="fields"></param>
        /// <returns></returns>
        public static void SetEntity(this Element elm, string schemaName, params FieldInfo[] fields)
        {
            if (elm is null)
            {
                throw new ArgumentNullException(nameof(elm));
            }

            if (schemaName is null)
            {
                throw new ArgumentNullException(nameof(schemaName));
            }

            if (fields is null)
            {
                throw new ArgumentNullException(nameof(fields));
            }

            var guid = Guid.NewGuid();

            var schemaBuilder = new SchemaBuilder(guid);

            schemaBuilder.SetReadAccessLevel(AccessLevel.Public);

            schemaBuilder.SetWriteAccessLevel(AccessLevel.Public);

            schemaBuilder.SetSchemaName(schemaName);

            foreach (var field in fields)
            {
                switch (field.FieldType)
                {
                case SchemaFieldType.Simple:
                    schemaBuilder.AddSimpleField(field.FieldName, field.DataType);

                    break;

                case SchemaFieldType.List:
                    schemaBuilder.AddArrayField(field.FieldName, field.DataType);

                    break;

                case SchemaFieldType.Dictionary:
                    schemaBuilder.AddMapField(field.FieldName, field.KeyType, field.ValueType);

                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            elm.SetEntity(new Entity(schemaBuilder.Finish()));
        }
Esempio n. 13
0
        private static Guid FindOrCreateSchema(Document doc)
        {
            // find schema
            RvtSchema = Schema.Lookup(RvtGuid);

            try
            {
                // Find or read subschemas needed
                Guid provGuid = Provider.FindOrCreateSchema(doc);
                Guid servGuid = Service.FindOrCreateSchema(doc);

                // create schema if not found
                if (RvtSchema == null)
                {
                    // Start transaction
                    Transaction createSchema = new Transaction(doc, "Create Bimbot Schema");
                    createSchema.Start();

                    // Build schema
                    SchemaBuilder schemaBldr = new SchemaBuilder(RvtGuid);

                    // Set read and write access attributes and a name
                    schemaBldr.SetReadAccessLevel(AccessLevel.Application);
                    schemaBldr.SetWriteAccessLevel(AccessLevel.Application);
                    schemaBldr.SetApplicationGUID(RevitBimbot.ApplicationGuid);
                    schemaBldr.SetVendorId(RevitBimbot.VendorId);
                    schemaBldr.SetSchemaName("BimBotDocument");

                    // create a field to store services
                    FieldBuilder fieldBldr = schemaBldr.AddMapField(ProvidersField, typeof(string), typeof(Entity));
                    fieldBldr.SetDocumentation("Dictionary of providers by url of service(s) in this project.");
                    fieldBldr.SetSubSchemaGUID(provGuid);

                    fieldBldr = schemaBldr.AddArrayField(ServicesField, typeof(Entity));
                    fieldBldr.SetDocumentation("List of services assigned to this project.");
                    fieldBldr.SetSubSchemaGUID(servGuid);

                    RvtSchema = schemaBldr.Finish(); // register the Schema object
                    createSchema.Commit();
                }
                else
                {
                    RvtSchema = Schema.Lookup(RvtGuid);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            return(RvtGuid);
        }
Esempio n. 14
0
        /// 添加字段
        /// <summary>
        ///  构造函数,创建schema 表
        /// </summary>
        private SchemaOpr()
        {
            //创建dictionary方式的schema
            System.Guid   guid    = GetCurGuid();
            SchemaBuilder builder = new SchemaBuilder(guid);

            // Set name to this schema builder

            builder.SetSchemaName("PmSchemaComn");
            builder.SetDocumentation("品茗通用的数据扩展结构");

            // Set read and write access levels

            builder.SetReadAccessLevel(AccessLevel.Public);
            builder.SetWriteAccessLevel(AccessLevel.Public);

            // 版本号,升级用
            builder.AddSimpleField("versionNum", typeof(short));

            // string元素
            builder.AddMapField("parms_str", typeof(string), typeof(string));

            // double元素
            FieldBuilder fb = builder.AddMapField("parms_double", typeof(string), typeof(double));

            fb.SetUnitType(UnitType.UT_Length);

            // element元素
            builder.AddMapField("parms_element", typeof(string), typeof(ElementId));

            // 表格元素
            builder.AddArrayField("tables_name", typeof(string));      //段名称
            builder.AddArrayField("tables_postion", typeof(int));      //段的二进制位置
            builder.AddArrayField("tables_content", typeof(byte));     //段的内容

            //
            m_schema = builder.Finish();
        }
Esempio n. 15
0
 /// <summary>
 /// the IFC File Header
 /// </summary>
 public IFCFileHeader()
 {
     if (m_schema == null)
     {
         m_schema = Schema.Lookup(s_schemaId);
     }
     if (m_schema == null)
     {
         SchemaBuilder fileHeaderBuilder = new SchemaBuilder(s_schemaId);
         fileHeaderBuilder.SetSchemaName("IFCFileHeader");
         fileHeaderBuilder.AddMapField(s_FileHeaderMapField, typeof(String), typeof(String));
         m_schema = fileHeaderBuilder.Finish();
     }
 }
        private Schema CreateComplexSchema()
        {
            SchemaBuilder schemaBuilder =
                new SchemaBuilder(new Guid("1899FD3C-7046-4B53-945A-AA1370B8C577"));

            schemaBuilder.SetSchemaName("ComplexSchema");

            var mapField = schemaBuilder.AddMapField("MapField", typeof(int), typeof(Entity));

            mapField.SetSubSchemaGUID(new Guid("4E5B6F62-B8B3-4A2F-9B06-DDD953D4D4BC"));
            mapField.SetDocumentation("Map field documentation");

            return(schemaBuilder.Finish());
        }
Esempio n. 17
0
 /// <summary>
 /// IFC address initialization
 /// </summary>
 public IFCAddress()
 {
     if (m_schema == null)
     {
         m_schema = Schema.Lookup(s_schemaId);
     }
     if (m_schema == null)
     {
         SchemaBuilder addressBuilder = new SchemaBuilder(s_schemaId);
         addressBuilder.SetSchemaName("IFCAddress");
         addressBuilder.AddMapField(s_addressMapField, typeof(String), typeof(String));
         m_schema = addressBuilder.Finish();
     }
 }
 /// <summary>
 /// the IFC File Header
 /// </summary>
 public IFCFileHeader()
 {
     if (m_schema == null)
     {
         m_schema = Schema.Lookup(s_schemaId);
     }
     if (m_schema == null)
     {
         SchemaBuilder fileHeaderBuilder = new SchemaBuilder(s_schemaId);
         fileHeaderBuilder.SetSchemaName("IFCFileHeader");
         fileHeaderBuilder.AddMapField(s_FileHeaderMapField, typeof(String), typeof(String));
         m_schema = fileHeaderBuilder.Finish();
     }
 }
Esempio n. 19
0
 /// <summary>
 /// IFC address initialization
 /// </summary>
 public IFCAddress()
 {
     if (m_schema == null)
     {
         m_schema = Schema.Lookup(s_schemaId);
     }
     if (m_schema == null)
     {
         SchemaBuilder addressBuilder = new SchemaBuilder(s_schemaId);
         addressBuilder.SetSchemaName("IFCAddress");
         addressBuilder.AddMapField(s_addressMapField, typeof(String), typeof(String));
         m_schema = addressBuilder.Finish();
     }
 }
Esempio n. 20
0
        private static Schema create_AutoGeneratedElementMgrSchema()
        {
            SchemaBuilder sb = new SchemaBuilder(Guid_AutoGeneratedElementMgrSchema);

            sb.SetSchemaName("AutoGeneratedElementMgrSchema");
            sb.SetReadAccessLevel(AccessLevel.Public);
            FieldBuilder fb1 = sb.AddMapField("ElementListOfId", typeof(string), typeof(Entity)); //addin_id / element_list_entity

            fb1.SetSubSchemaGUID(Guid_ElementListOfId);

            Schema sm = sb.Finish();

            return(sm);
        }
Esempio n. 21
0
        /// <summary>
        /// Creates an dictionary type field builder by field name.
        /// </summary>
        /// <typeparam name="K"></typeparam>
        /// <typeparam name="V"></typeparam>
        /// <param name="schemaBuilder"></param>
        /// <param name="fieldName"></param>
        /// <param name="unitType"></param>
        /// <param name="decription"></param>
        /// <returns></returns>
        public static FieldBuilder CreateDictField <K, V>(this SchemaBuilder schemaBuilder, string fieldName, UnitType unitType, string decription = null)
        {
            var result = schemaBuilder.AddMapField(fieldName, typeof(K), typeof(V));

            result.SetUnitType(unitType);

            if (decription == null)
            {
                decription = fieldName;
            }

            result.SetDocumentation(decription);

            return(result);
        }
Esempio n. 22
0
 public ExtensibleStorage(string guid, string SchemaName, string FieldName, Type KeyType, Type ValueType, string Fielddocumentation)
 {
     this.Schema_Name   = SchemaName;
     this.Field_Name    = FieldName;
     this.Key_Type      = KeyType;
     this.Value_Type    = ValueType;
     this.schemaBuilder = new SchemaBuilder(new Guid(guid));
     schemaBuilder.SetReadAccessLevel(AccessLevel.Public);
     schemaBuilder.SetWriteAccessLevel(AccessLevel.Public);
     // create a field to store a string map
     this.FieldDocumentation = Fielddocumentation;
     this.fieldBuilder       = schemaBuilder.AddMapField(Field_Name, Key_Type, Value_Type);
     fieldBuilder.SetDocumentation(FieldDocumentation);
     schemaBuilder.SetSchemaName(Schema_Name);
     schema = schemaBuilder.Finish();
 }
        private static Schema CreateSchema()
        {
            Schema schema = null;

            try
            {
                SchemaBuilder schemaBuilder = new SchemaBuilder(schemaId);
                schemaBuilder.SetSchemaName("RoomElevationCreator");
                schemaBuilder.AddSimpleField(s_RoomNumber, typeof(string));
                schemaBuilder.AddSimpleField(s_RoomName, typeof(string));
                schemaBuilder.AddSimpleField(s_IsLinked, typeof(bool));
                schemaBuilder.AddSimpleField(s_RoomId, typeof(ElementId));
                schemaBuilder.AddSimpleField(s_RvtInstanceId, typeof(ElementId));
                schemaBuilder.AddSimpleField(s_KeyMarkId, typeof(ElementId));
                schemaBuilder.AddMapField(s_Elevations, typeof(int) /*viewId*/, typeof(int) /*markId*/);

                schema = schemaBuilder.Finish();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to create schema.\n" + ex.Message, "Create Schema", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(schema);
        }
        /// <summary>
        /// Updates the setups to save into the document.
        /// </summary>
        public void UpdateSavedConfigurations()
        {
            // delete the old schema and the DataStorage.
            if (m_schema == null)
            {
                m_schema = Schema.Lookup(s_schemaId);
            }
            if (m_schema != null)
            {
                IList <DataStorage> oldSavedConfigurations = GetSavedConfigurations(m_schema);
                if (oldSavedConfigurations.Count > 0)
                {
                    Transaction deleteTransaction = new Transaction(IFCCommandOverrideApplication.TheDocument,
                                                                    Properties.Resources.DeleteOldSetups);
                    try
                    {
                        deleteTransaction.Start();
                        List <ElementId> dataStorageToDelete = new List <ElementId>();
                        foreach (DataStorage dataStorage in oldSavedConfigurations)
                        {
                            dataStorageToDelete.Add(dataStorage.Id);
                        }
                        IFCCommandOverrideApplication.TheDocument.Delete(dataStorageToDelete);
                        deleteTransaction.Commit();
                    }
                    catch (System.Exception)
                    {
                        if (deleteTransaction.HasStarted())
                        {
                            deleteTransaction.RollBack();
                        }
                    }
                }
            }

            // update the configurations to new map schema.
            if (m_mapSchema == null)
            {
                m_mapSchema = Schema.Lookup(s_mapSchemaId);
            }

            // Are there any setups to save or resave?
            List <IFCExportConfiguration> setupsToSave = new List <IFCExportConfiguration>();

            foreach (IFCExportConfiguration configuration in m_configurations.Values)
            {
                if (configuration.IsBuiltIn)
                {
                    continue;
                }

                // Store in-session settings in the cached in-session configuration
                if (configuration.IsInSession)
                {
                    IFCExportConfiguration.SetInSession(configuration);
                    continue;
                }

                setupsToSave.Add(configuration);
            }

            // If there are no setups to save, and if the schema is not present (which means there are no
            // previously existing setups which might have been deleted) we can skip the rest of this method.
            if (setupsToSave.Count <= 0 && m_mapSchema == null)
            {
                return;
            }

            if (m_mapSchema == null)
            {
                SchemaBuilder builder = new SchemaBuilder(s_mapSchemaId);
                builder.SetSchemaName("IFCExportConfigurationMap");
                builder.AddMapField(s_configMapField, typeof(String), typeof(String));
                m_mapSchema = builder.Finish();
            }

            // Overwrite all saved configs with the new list
            Transaction transaction = new Transaction(IFCCommandOverrideApplication.TheDocument, Properties.Resources.UpdateExportSetups);

            try
            {
                transaction.Start();
                IList <DataStorage> savedConfigurations = GetSavedConfigurations(m_mapSchema);
                int savedConfigurationCount             = savedConfigurations.Count <DataStorage>();
                int savedConfigurationIndex             = 0;
                foreach (IFCExportConfiguration configuration in setupsToSave)
                {
                    DataStorage configStorage;
                    if (savedConfigurationIndex >= savedConfigurationCount)
                    {
                        configStorage = DataStorage.Create(IFCCommandOverrideApplication.TheDocument);
                    }
                    else
                    {
                        configStorage = savedConfigurations[savedConfigurationIndex];
                        savedConfigurationIndex++;
                    }

                    Entity mapEntity = new Entity(m_mapSchema);
                    IDictionary <string, string> mapData = new Dictionary <string, string>();
                    mapData.Add(s_setupName, configuration.Name);
                    mapData.Add(s_setupVersion, configuration.IFCVersion.ToString());
                    mapData.Add(s_setupFileFormat, configuration.IFCFileType.ToString());
                    mapData.Add(s_setupSpaceBoundaries, configuration.SpaceBoundaries.ToString());
                    mapData.Add(s_setupQTO, configuration.ExportBaseQuantities.ToString());
                    mapData.Add(s_setupCurrentView, configuration.VisibleElementsOfCurrentView.ToString());
                    mapData.Add(s_splitWallsAndColumns, configuration.SplitWallsAndColumns.ToString());
                    mapData.Add(s_setupExport2D, configuration.Export2DElements.ToString());
                    mapData.Add(s_setupExportRevitProps, configuration.ExportInternalRevitPropertySets.ToString());
                    mapData.Add(s_setupExportIFCCommonProperty, configuration.ExportIFCCommonPropertySets.ToString());
                    mapData.Add(s_setupUse2DForRoomVolume, configuration.Use2DRoomBoundaryForVolume.ToString());
                    mapData.Add(s_setupUseFamilyAndTypeName, configuration.UseFamilyAndTypeNameForReference.ToString());
                    mapData.Add(s_setupExportPartsAsBuildingElements, configuration.ExportPartsAsBuildingElements.ToString());
                    mapData.Add(s_useActiveViewGeometry, configuration.UseActiveViewGeometry.ToString());
                    mapData.Add(s_setupExportSpecificSchedules, configuration.ExportSpecificSchedules.ToString());
                    mapData.Add(s_setupExportBoundingBox, configuration.ExportBoundingBox.ToString());
                    mapData.Add(s_setupExportSolidModelRep, configuration.ExportSolidModelRep.ToString());
                    mapData.Add(s_setupExportSchedulesAsPsets, configuration.ExportSchedulesAsPsets.ToString());
                    mapData.Add(s_setupExportUserDefinedPsets, configuration.ExportUserDefinedPsets.ToString());
                    mapData.Add(s_setupExportUserDefinedPsetsFileName, configuration.ExportUserDefinedPsetsFileName);
                    mapData.Add(s_setupExportUserDefinedParameterMapping, configuration.ExportUserDefinedParameterMapping.ToString());
                    mapData.Add(s_setupExportUserDefinedParameterMappingFileName, configuration.ExportUserDefinedParameterMappingFileName);
                    mapData.Add(s_setupExportLinkedFiles, configuration.ExportLinkedFiles.ToString());
                    mapData.Add(s_setupIncludeSiteElevation, configuration.IncludeSiteElevation.ToString());
                    mapData.Add(s_setupStoreIFCGUID, configuration.StoreIFCGUID.ToString());
                    mapData.Add(s_setupActivePhase, configuration.ActivePhaseId.ToString());
                    mapData.Add(s_setupExportRoomsInView, configuration.ExportRoomsInView.ToString());
                    mapData.Add(s_useOnlyTriangulation, configuration.UseOnlyTriangulation.ToString());
                    mapData.Add(s_excludeFilter, configuration.ExcludeFilter.ToString());
                    mapData.Add(s_setupSitePlacement, configuration.SitePlacement.ToString());
                    mapData.Add(s_useTypeNameOnlyForIfcType, configuration.UseTypeNameOnlyForIfcType.ToString());
                    mapData.Add(s_useVisibleRevitNameAsEntityName, configuration.UseVisibleRevitNameAsEntityName.ToString());
                    // For COBie v2.4
                    mapData.Add(s_cobieCompanyInfo, configuration.COBieCompanyInfo);
                    mapData.Add(s_cobieProjectInfo, configuration.COBieProjectInfo);
                    mapData.Add(s_includeSteelElements, configuration.IncludeSteelElements.ToString());

                    mapEntity.Set <IDictionary <string, String> >(s_configMapField, mapData);
                    configStorage.SetEntity(mapEntity);
                }

                List <ElementId> elementsToDelete = new List <ElementId>();
                for (; savedConfigurationIndex < savedConfigurationCount; savedConfigurationIndex++)
                {
                    DataStorage configStorage = savedConfigurations[savedConfigurationIndex];
                    elementsToDelete.Add(configStorage.Id);
                }
                if (elementsToDelete.Count > 0)
                {
                    IFCCommandOverrideApplication.TheDocument.Delete(elementsToDelete);
                }

                transaction.Commit();
            }
            catch (System.Exception)
            {
                if (transaction.HasStarted())
                {
                    transaction.RollBack();
                }
            }
        }
        /// <summary>
        /// Updates the setups to save into the document.
        /// </summary>
        /// <param name="document">The document storing the saved configuration.</param>
        public void UpdateSavedConfigurations(Document document)
        {
            // delete the old schema and the DataStorage.
            if (m_schema == null)
            {
                m_schema = Schema.Lookup(s_schemaId);
            }
            if (m_schema != null)
            {
                IList<DataStorage> oldSavedConfigurations = GetSavedConfigurations(document, m_schema);
                if (oldSavedConfigurations.Count > 0)
                {
                    Transaction deleteTransaction = new Transaction(document, "Delete old IFC export setups");
                    deleteTransaction.Start();
                    List<ElementId> dataStorageToDelete = new List<ElementId>();
                    foreach (DataStorage dataStorage in oldSavedConfigurations)
                    {
                        dataStorageToDelete.Add(dataStorage.Id);
                    }
                    document.Delete(dataStorageToDelete);
                    deleteTransaction.Commit();
                }
            }

            // update the configurations to new map schema.
            if (m_mapSchema == null)
            {
                m_mapSchema = Schema.Lookup(s_mapSchemaId);
            }

            // Are there any setups to save or resave?
            List<IFCExportConfiguration> setupsToSave = new List<IFCExportConfiguration>();
            foreach (IFCExportConfiguration configuration in m_configurations.Values)
            {
                if (configuration.IsBuiltIn)
                    continue;

                // Store in-session settings in the cached in-session configuration
                if (configuration.IsInSession)
                {
                    IFCExportConfiguration.SetInSession(configuration);
                    continue;
                }

                setupsToSave.Add(configuration);
           }

           // If there are no setups to save, and if the schema is not present (which means there are no
           // previously existing setups which might have been deleted) we can skip the rest of this method.
            if (setupsToSave.Count <= 0 && m_mapSchema == null)
               return;

           if (m_mapSchema == null)
           {
               SchemaBuilder builder = new SchemaBuilder(s_mapSchemaId);
               builder.SetSchemaName("IFCExportConfigurationMap");
               builder.AddMapField(s_configMapField, typeof(String), typeof(String));
               m_mapSchema = builder.Finish();
           }

           // Overwrite all saved configs with the new list
           Transaction transaction = new Transaction(document, "Update IFC export setups");
           transaction.Start();
           IList<DataStorage> savedConfigurations = GetSavedConfigurations(document, m_mapSchema);
           int savedConfigurationCount = savedConfigurations.Count<DataStorage>();
           int savedConfigurationIndex = 0;
           foreach (IFCExportConfiguration configuration in setupsToSave)
           {
                DataStorage configStorage;
                if (savedConfigurationIndex >= savedConfigurationCount)
                {
                    configStorage = DataStorage.Create(document);
                }
                else
                {
                    configStorage = savedConfigurations[savedConfigurationIndex];
                    savedConfigurationIndex ++;
                }             

                Entity mapEntity = new Entity(m_mapSchema);
                IDictionary<string, string> mapData = new Dictionary<string, string>();
                mapData.Add(s_setupName, configuration.Name);
                mapData.Add(s_setupDescription, configuration.Description);
                mapData.Add(s_setupVersion, configuration.IFCVersion.ToString());
                mapData.Add(s_setupFileFormat, configuration.IFCFileType.ToString());
                mapData.Add(s_setupSpaceBoundaries, configuration.SpaceBoundaries.ToString());
                mapData.Add(s_setupQTO, configuration.ExportBaseQuantities.ToString());
                mapData.Add(s_setupCurrentView, configuration.VisibleElementsOfCurrentView.ToString());
                mapData.Add(s_splitWallsAndColumns, configuration.SplitWallsAndColumns.ToString());
                mapData.Add(s_setupExport2D, configuration.Export2DElements.ToString());
                mapData.Add(s_setupExportRevitProps, configuration.ExportInternalRevitPropertySets.ToString());
                mapData.Add(s_setupExportIFCCommonProperty, configuration.ExportIFCCommonPropertySets.ToString());
                mapData.Add(s_setupUse2DForRoomVolume, configuration.Use2DRoomBoundaryForVolume.ToString());
                mapData.Add(s_setupUseFamilyAndTypeName, configuration.UseFamilyAndTypeNameForReference.ToString());
                mapData.Add(s_setupExportPartsAsBuildingElements, configuration.ExportPartsAsBuildingElements.ToString());
                mapData.Add(s_setupExportSurfaceStyles, configuration.ExportSurfaceStyles.ToString());
                mapData.Add(s_setupExportAdvancedSweptSolids, configuration.ExportAdvancedSweptSolids.ToString());
                mapData.Add(s_setupExportBoundingBox, configuration.ExportBoundingBox.ToString());
                mapEntity.Set<IDictionary<string, String>>(s_configMapField, mapData);

                configStorage.SetEntity(mapEntity);
            }

            List<ElementId> elementsToDelete = new List<ElementId>();
            for (; savedConfigurationIndex < savedConfigurationCount; savedConfigurationIndex++)
            {
                DataStorage configStorage = savedConfigurations[savedConfigurationIndex];
                elementsToDelete.Add(configStorage.Id);
            }
            if (elementsToDelete.Count > 0)
                document.Delete(elementsToDelete);

            transaction.Commit();
        }
        /// <summary>
        /// Updates the setups to save into the document.
        /// </summary>
        public void UpdateSavedConfigurations()
        {
            // delete the old schema and the DataStorage.
            if (m_schema == null)
            {
                m_schema = Schema.Lookup(s_schemaId);
            }
            if (m_schema != null)
            {
                IList<DataStorage> oldSavedConfigurations = GetSavedConfigurations(m_schema);
                if (oldSavedConfigurations.Count > 0)
                {
                    Transaction deleteTransaction = new Transaction(IFCCommandOverrideApplication.TheDocument, 
                        Properties.Resources.DeleteOldSetups);
                    try
                    {
                        deleteTransaction.Start();
                        List<ElementId> dataStorageToDelete = new List<ElementId>();
                        foreach (DataStorage dataStorage in oldSavedConfigurations)
                        {
                            dataStorageToDelete.Add(dataStorage.Id);
                        }
                        IFCCommandOverrideApplication.TheDocument.Delete(dataStorageToDelete);
                        deleteTransaction.Commit();
                    }
                    catch (System.Exception)
                    {
                        if (deleteTransaction.HasStarted())
                            deleteTransaction.RollBack();
                    }
                }
            }

            // update the configurations to new map schema.
            if (m_mapSchema == null)
            {
                m_mapSchema = Schema.Lookup(s_mapSchemaId);
            }

            // Are there any setups to save or resave?
            List<IFCExportConfiguration> setupsToSave = new List<IFCExportConfiguration>();
            foreach (IFCExportConfiguration configuration in m_configurations.Values)
            {
                if (configuration.IsBuiltIn)
                    continue;

                // Store in-session settings in the cached in-session configuration
                if (configuration.IsInSession)
                {
                    IFCExportConfiguration.SetInSession(configuration);
                    continue;
                }

                setupsToSave.Add(configuration);
           }

           // If there are no setups to save, and if the schema is not present (which means there are no
           // previously existing setups which might have been deleted) we can skip the rest of this method.
            if (setupsToSave.Count <= 0 && m_mapSchema == null)
               return;

           if (m_mapSchema == null)
           {
               SchemaBuilder builder = new SchemaBuilder(s_mapSchemaId);
               builder.SetSchemaName("IFCExportConfigurationMap");
               builder.AddMapField(s_configMapField, typeof(String), typeof(String));
               m_mapSchema = builder.Finish();
           }

           // Overwrite all saved configs with the new list
           Transaction transaction = new Transaction(IFCCommandOverrideApplication.TheDocument, Properties.Resources.UpdateExportSetups);
           try
           {
               transaction.Start();
               IList<DataStorage> savedConfigurations = GetSavedConfigurations(m_mapSchema);
               int savedConfigurationCount = savedConfigurations.Count<DataStorage>();
               int savedConfigurationIndex = 0;
               foreach (IFCExportConfiguration configuration in setupsToSave)
               {
                   DataStorage configStorage;
                   if (savedConfigurationIndex >= savedConfigurationCount)
                   {
                       configStorage = DataStorage.Create(IFCCommandOverrideApplication.TheDocument);
                   }
                   else
                   {
                       configStorage = savedConfigurations[savedConfigurationIndex];
                       savedConfigurationIndex++;
                   }

                   Entity mapEntity = new Entity(m_mapSchema);
                   IDictionary<string, string> mapData = new Dictionary<string, string>();
                   mapData.Add(s_setupName, configuration.Name);
                   mapData.Add(s_setupVersion, configuration.IFCVersion.ToString());
                   mapData.Add(s_setupFileFormat, configuration.IFCFileType.ToString());
                   mapData.Add(s_setupSpaceBoundaries, configuration.SpaceBoundaries.ToString());
                   mapData.Add(s_setupQTO, configuration.ExportBaseQuantities.ToString());
                   mapData.Add(s_setupCurrentView, configuration.VisibleElementsOfCurrentView.ToString());
                   mapData.Add(s_splitWallsAndColumns, configuration.SplitWallsAndColumns.ToString());
                   mapData.Add(s_setupExport2D, configuration.Export2DElements.ToString());
                   mapData.Add(s_setupExportRevitProps, configuration.ExportInternalRevitPropertySets.ToString());
                   mapData.Add(s_setupExportIFCCommonProperty, configuration.ExportIFCCommonPropertySets.ToString());
                   mapData.Add(s_setupUse2DForRoomVolume, configuration.Use2DRoomBoundaryForVolume.ToString());
                   mapData.Add(s_setupUseFamilyAndTypeName, configuration.UseFamilyAndTypeNameForReference.ToString());
                   mapData.Add(s_setupExportPartsAsBuildingElements, configuration.ExportPartsAsBuildingElements.ToString());
                   mapData.Add(s_useActiveViewGeometry, configuration.UseActiveViewGeometry.ToString());
                   mapData.Add(s_setupExportSpecificSchedules, configuration.ExportSpecificSchedules.ToString());
                   mapData.Add(s_setupExportBoundingBox, configuration.ExportBoundingBox.ToString());
                   mapData.Add(s_setupExportSolidModelRep, configuration.ExportSolidModelRep.ToString());
                   mapData.Add(s_setupExportSchedulesAsPsets, configuration.ExportSchedulesAsPsets.ToString());
                   mapData.Add(s_setupExportUserDefinedPsets, configuration.ExportUserDefinedPsets.ToString());
                   mapData.Add(s_setupExportUserDefinedPsetsFileName, configuration.ExportUserDefinedPsetsFileName);
                   mapData.Add(s_setupExportLinkedFiles, configuration.ExportLinkedFiles.ToString());
                   mapData.Add(s_setupIncludeSiteElevation, configuration.IncludeSiteElevation.ToString());
                   mapData.Add(s_setupStoreIFCGUID, configuration.StoreIFCGUID.ToString());
                   mapData.Add(s_setupActivePhase, configuration.ActivePhaseId.ToString());
                   mapData.Add(s_setupExportRoomsInView, configuration.ExportRoomsInView.ToString());
                   mapEntity.Set<IDictionary<string, String>>(s_configMapField, mapData);

                   configStorage.SetEntity(mapEntity);
               }

               List<ElementId> elementsToDelete = new List<ElementId>();
               for (; savedConfigurationIndex < savedConfigurationCount; savedConfigurationIndex++)
               {
                   DataStorage configStorage = savedConfigurations[savedConfigurationIndex];
                   elementsToDelete.Add(configStorage.Id);
               }
               if (elementsToDelete.Count > 0)
                   IFCCommandOverrideApplication.TheDocument.Delete(elementsToDelete);

               transaction.Commit();
           }
           catch (System.Exception)
           {
               if (transaction.HasStarted())
                   transaction.RollBack();
           }
        }
Esempio n. 27
0
        /// <summary>
        /// Create a new Autodesk.Revit.DB.ExtensibleStorage.SchemaBuilder and Schema from
        /// the data in the SchemaWrapper.
        /// </summary>
        public void FinishSchema()
        {
            //Create the Autodesk.Revit.DB.ExtensibleStorage.SchemaBuilder that actually builds the schema
            m_SchemaBuilder = new SchemaBuilder(new Guid(m_SchemaDataWrapper.SchemaId));


            //We will add a new field to our schema from each FieldData object in our SchemaWrapper
            foreach (FieldData currentFieldData in m_SchemaDataWrapper.DataList)
            {
                //If the current field's type is a supported system type (int, string, etc...),
                //we can instantiate it with Type.GetType().  If the current field's type is a supported Revit API type
                //(XYZ, elementID, etc...), we need to call GetType from the RevitAPI.dll assembly object.
                Type fieldType = null;
                try
                {
                    fieldType = Type.GetType(currentFieldData.Type, true, true);
                }

                catch (Exception ex) //Get the type from the Revit API assembly if it is not a system type.
                {
                    Debug.WriteLine(ex.ToString());
                    try
                    {
                        //Get the field from the Revit API assembly.
                        fieldType = m_Assembly.GetType(currentFieldData.Type);
                    }

                    catch (Exception exx)
                    {
                        Debug.WriteLine("Error getting type: " + exx.ToString());
                        throw;
                    }
                }


                //Now that we have the data type of field we need to add, we need to call either
                //SchemaBuilder.AddSimpleField, AddArrayField, or AddMapField.

                FieldBuilder currentFieldBuilder = null;
                Guid         subSchemaId         = Guid.Empty;
                Type[]       genericParams       = null;


                if (currentFieldData.SubSchema != null)
                {
                    subSchemaId = new Guid(currentFieldData.SubSchema.Data.SchemaId);
                }

                //If our data type is a generic, it is an IList<> or an IDictionary<>, so it's an array or map type
                if (fieldType.IsGenericType)
                {
                    Type tGeneric = fieldType.GetGenericTypeDefinition(); //tGeneric will be either an IList<> or an IDictionary<>.

                    //Create an IList<> or an IDictionary<> to compare against tGeneric.
                    Type iDictionaryType = typeof(IDictionary <int, int>).GetGenericTypeDefinition();
                    Type iListType       = typeof(IList <int>).GetGenericTypeDefinition();

                    genericParams = fieldType.GetGenericArguments(); //Get the actual data type(s) stored in the field's IList<> or IDictionary<>
                    if (tGeneric == iDictionaryType)
                    {
                        //Pass the key and value type of our dictionary type to AddMapField.
                        currentFieldBuilder = m_SchemaBuilder.AddMapField(currentFieldData.Name, genericParams[0], genericParams[1]);
                    }
                    else if (tGeneric == iListType)
                    {
                        //Pass the value type of our list type to AddArrayField.
                        currentFieldBuilder = m_SchemaBuilder.AddArrayField(currentFieldData.Name, genericParams[0]);
                    }
                    else
                    {
                        throw new Exception("Generic type is neither IList<> nor IDictionary<>, cannot process.");
                    }
                }
                else
                {
                    //The simpler case -- just add field using a name and a System.Type.
                    currentFieldBuilder = m_SchemaBuilder.AddSimpleField(currentFieldData.Name, fieldType);
                }

                if ( //if we're dealing with an Entity as a simple field, map field, or list field and need to do recursion...
                    (fieldType == (typeof(Entity)))
                    ||
                    (fieldType.IsGenericType && ((genericParams[0] == (typeof(Entity))) || ((genericParams.Length > 1) && (genericParams[1] == typeof(Entity)))))
                    )
                {
                    currentFieldBuilder.SetSubSchemaGUID(subSchemaId); //Set the SubSchemaID if our field
                    currentFieldData.SubSchema.FinishSchema();         //Recursively create the schema for the subSchema.
                }

                if (!currentFieldData.Spec.Empty())
                {
                    currentFieldBuilder.SetSpec(currentFieldData.Spec);
                }
            }

            //Set all the top level data in the schema we are generating.
            m_SchemaBuilder.SetReadAccessLevel(this.Data.ReadAccess);
            m_SchemaBuilder.SetWriteAccessLevel(this.Data.WriteAccess);
            m_SchemaBuilder.SetVendorId(this.Data.VendorId);
            m_SchemaBuilder.SetApplicationGUID(new Guid(this.Data.ApplicationId));
            m_SchemaBuilder.SetDocumentation(this.Data.Documentation);
            m_SchemaBuilder.SetSchemaName(this.Data.Name);


            //Actually finish creating the Autodesk.Revit.DB.ExtensibleStorage.Schema.
            m_Schema = m_SchemaBuilder.Finish();
        }