/// <summary>
 /// Constructs a copy from a defined configuration.
 /// </summary>
 /// <param name="other">The configuration to copy.</param>
 private IFCExporterConfiguration(IFCExporterConfiguration other)
 {
     Name                                      = other.Name;
     IFCFVersion                               = other.IFCFVersion;
     IFCFileType                               = other.IFCFileType;
     SpaceBoundaries                           = other.SpaceBoundaries;
     ExportBaseQuantities                      = other.ExportBaseQuantities;
     SplitWallsAndColumns                      = other.SplitWallsAndColumns;
     ExportInternalRevitPropertySets           = other.ExportInternalRevitPropertySets;
     ExportIFCCommonPropertySets               = other.ExportIFCCommonPropertySets;
     Export2DElements                          = other.Export2DElements;
     VisibleElementsOfCurrentView              = other.VisibleElementsOfCurrentView;
     Use2DRoomBoundaryForVolume                = other.Use2DRoomBoundaryForVolume;
     UseFamilyAndTypeNameForReference          = other.UseFamilyAndTypeNameForReference;
     ExportPartsAsBuildingElements             = other.ExportPartsAsBuildingElements;
     UseActiveViewGeometry                     = other.UseActiveViewGeometry;
     ExportSpecificSchedules                   = other.ExportSpecificSchedules;
     ExportBoundingBox                         = other.ExportBoundingBox;
     ExportSolidModelRep                       = other.ExportSolidModelRep;
     ExportSchedulesAsPsets                    = other.ExportSchedulesAsPsets;
     ExportUserDefinedPsets                    = other.ExportUserDefinedPsets;
     ExportUserDefinedPsetsFileName            = other.ExportUserDefinedPsetsFileName;
     ExportUserDefinedParameterMapping         = other.ExportUserDefinedParameterMapping;
     ExportUserDefinedParameterMappingFileName = other.ExportUserDefinedParameterMappingFileName;
     ExportLinkedFiles                         = other.ExportLinkedFiles;
     IncludeSiteElevation                      = other.IncludeSiteElevation;
     TessellationLevelOfDetail                 = other.TessellationLevelOfDetail;
     StoreIFCGUID                              = other.StoreIFCGUID;
     _isBuiltInConfiguration                   = other._isBuiltInConfiguration;
     //this.m_isInSession = other.m_isInSession;
     ActivePhaseId     = other.ActivePhaseId;
     ExportRoomsInView = other.ExportRoomsInView;
 }
        /// <summary>
        /// Creates a builtIn configuration by particular options.
        /// </summary>
        /// <param name="name">The configuration name.</param>
        /// <param name="ifcVersion">The IFCVersion.</param>
        /// <param name="spaceBoundaries">The space boundary level.</param>
        /// <param name="exportBaseQuantities">The ExportBaseQuantities.</param>
        /// <param name="splitWalls">bool indicating if walls and columns should be split by level</param>
        /// <param name="internalSets">bool indicating if the export should use the internal propertysets</param>
        /// <param name="schedulesAsPSets">bool indicating if schedules shoudl be exported as propertysets</param>
        /// <param name="userDefinedPSets">bool indicating if userdefined propertysets should be used</param>
        /// <param name="userDefinedParameterMapping">bool indicating if userdefind parametermappings should be used</param>
        /// <param name="PlanElems2D">The Export2DElements option.</param>
        /// <param name="exportBoundingBox">The exportBoundingBox option.</param>
        /// <param name="exportLinkedFiles">The exportLinkedFiles option.</param>
        /// <returns>The builtIn configuration.</returns>
        internal static IFCExporterConfiguration CreateBuiltInConfiguration(string name,
                                                                            IFCVersion ifcVersion,
                                                                            int spaceBoundaries,
                                                                            bool exportBaseQuantities,
                                                                            bool splitWalls,
                                                                            bool internalSets,
                                                                            bool schedulesAsPSets,
                                                                            bool userDefinedPSets,
                                                                            bool userDefinedParameterMapping,
                                                                            bool PlanElems2D,
                                                                            bool exportBoundingBox,
                                                                            bool exportLinkedFiles)
        {
            IFCExporterConfiguration configuration = new IFCExporterConfiguration();

            configuration.Name                                      = name;
            configuration.IFCFVersion                               = ifcVersion;
            configuration.IFCFileType                               = IFCFileFormat.Ifc;
            configuration.SpaceBoundaries                           = spaceBoundaries;
            configuration.ExportBaseQuantities                      = exportBaseQuantities;
            configuration.SplitWallsAndColumns                      = splitWalls;
            configuration.ExportInternalRevitPropertySets           = internalSets;
            configuration.ExportIFCCommonPropertySets               = true;
            configuration.Export2DElements                          = PlanElems2D;
            configuration.VisibleElementsOfCurrentView              = false;
            configuration.Use2DRoomBoundaryForVolume                = false;
            configuration.UseFamilyAndTypeNameForReference          = false;
            configuration.ExportPartsAsBuildingElements             = false;
            configuration.UseActiveViewGeometry                     = false;
            configuration.ExportSpecificSchedules                   = false;
            configuration.ExportBoundingBox                         = exportBoundingBox;
            configuration.ExportSolidModelRep                       = false;
            configuration.ExportSchedulesAsPsets                    = schedulesAsPSets;
            configuration.ExportUserDefinedPsets                    = userDefinedPSets;
            configuration.ExportUserDefinedPsetsFileName            = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\" + name + @".txt";
            configuration.ExportUserDefinedParameterMapping         = userDefinedParameterMapping;
            configuration.ExportUserDefinedParameterMappingFileName = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\ParameterMappingTable.txt";
            configuration.ExportLinkedFiles                         = exportLinkedFiles;
            configuration.IncludeSiteElevation                      = false;
            // The default tesselationLevelOfDetail will be low
            configuration.TessellationLevelOfDetail = 0.5;
            configuration.StoreIFCGUID            = false;
            configuration._isBuiltInConfiguration = true;
            //configuration.m_isInSession = false;
            configuration.ActivePhaseId     = ElementId.InvalidElementId;
            configuration.ExportRoomsInView = false;
            return(configuration);
        }
        /// <summary>
        /// Adds the built-in configurations to the map.
        /// </summary>
        internal void AddBuiltInConfigurations()
        {
            // These are the built-in configurations.  Provide a more extensible means of storage.
            // Order of construction: name, version, space boundaries, QTO, split walls, internal sets, 2d elems, boundingBox
#if LIMITEDIFC
            // Revit2016 only supports the following five IFC versions, subsequent revits support eight.
            Add(IFCExporterConfiguration.CreateBuiltInConfiguration("IFC2x3 Coordination View 2.0", IFCVersion.IFC2x3CV2, 0, false, false, false, false, false, false, false, false, false));
            Add(IFCExporterConfiguration.CreateBuiltInConfiguration("IFC2x3 Coordination View", IFCVersion.IFC2x3, 1, false, false, true, false, false, false, true, false, false));
            Add(IFCExporterConfiguration.CreateBuiltInConfiguration("IFC2x3 GSA Concept Design BIM 2010", IFCVersion.IFCCOBIE, 2, true, true, true, false, false, false, true, true, false));
            Add(IFCExporterConfiguration.CreateBuiltInConfiguration("IFC2x2 Coordination View", IFCVersion.IFC2x2, 1, false, false, true, false, false, false, false, false, false));
            Add(IFCExporterConfiguration.CreateBuiltInConfiguration("IFC2x2 Singapore BCA e-Plan Check", IFCVersion.IFCBCA, 1, false, true, true, false, false, false, false, false, false));
#else
            Add(IFCExporterConfiguration.CreateBuiltInConfiguration("IFC4 Reference View", IFCVersion.IFC4RV, 0, false, false, false, false, false, false, false, false, false));
            Add(IFCExporterConfiguration.CreateBuiltInConfiguration("IFC4 Design Transfer View", IFCVersion.IFC4DTV, 0, false, false, false, false, false, false, false, false, false));
            Add(IFCExporterConfiguration.CreateBuiltInConfiguration("IFC2x3 Coordination View 2.0", IFCVersion.IFC2x3CV2, 0, false, false, false, false, false, false, false, false, false));
            Add(IFCExporterConfiguration.CreateBuiltInConfiguration("IFC2x3 Coordination View", IFCVersion.IFC2x3, 1, false, false, true, false, false, false, true, false, false));
            Add(IFCExporterConfiguration.CreateBuiltInConfiguration("IFC2x3 GSA Concept Design BIM 2010", IFCVersion.IFCCOBIE, 2, true, true, true, false, false, false, true, true, false));
            Add(IFCExporterConfiguration.CreateBuiltInConfiguration("IFC2x3 Basic FM Handover View", IFCVersion.IFC2x3BFM, 1, true, true, false, false, false, false, true, false, false));
            Add(IFCExporterConfiguration.CreateBuiltInConfiguration("IFC2x2 Coordination View", IFCVersion.IFC2x2, 1, false, false, true, false, false, false, false, false, false));
            Add(IFCExporterConfiguration.CreateBuiltInConfiguration("IFC2x2 Singapore BCA e-Plan Check", IFCVersion.IFCBCA, 1, false, true, true, false, false, false, false, false, false));
            Add(IFCExporterConfiguration.CreateBuiltInConfiguration("IFC2x3 Extended FM Handover View", IFCVersion.IFC2x3FM, 1, true, false, false, true, true, false, true, true, false));
#endif
        }
 /// <summary>
 /// Adds a configuration to the map.
 /// </summary>
 /// <param name="configuration">The configuration.</param>
 internal void Add(IFCExporterConfiguration configuration)
 {
     Dict.Add(configuration.Name, configuration);
 }
        /// <summary>
        /// Adds the saved configuration from document to the map.
        /// </summary>
        internal void AddProjectConfigurations()
        {
            try
            {
                if (_schema == null)
                {
                    _schema = Schema.Lookup(_schemaId);
                }
                if (_mapSchema == null)
                {
                    _mapSchema = Schema.Lookup(_mapSchemaId);
                }

                if (_mapSchema != null)
                {
                    foreach (DataStorage storedSetup in GetProjectConfigurations(_mapSchema))
                    {
                        Entity configEntity = storedSetup.GetEntity(_mapSchema);
                        IDictionary <string, string> configMap     = configEntity.Get <IDictionary <string, string> >(s_configMapField);
                        IFCExporterConfiguration     configuration = IFCExporterConfiguration.CreateDefaultConfiguration();
                        if (configMap.ContainsKey(s_setupName))
                        {
                            configuration.Name = configMap[s_setupName];
                        }
                        if (configMap.ContainsKey(s_setupVersion))
                        {
                            configuration.IFCFVersion = (IFCVersion)Enum.Parse(typeof(IFCVersion), configMap[s_setupVersion]);
                        }
                        if (configMap.ContainsKey(s_setupFileFormat))
                        {
                            configuration.IFCFileType = (IFCFileFormat)Enum.Parse(typeof(IFCFileFormat), configMap[s_setupFileFormat]);
                        }
                        if (configMap.ContainsKey(s_setupSpaceBoundaries))
                        {
                            configuration.SpaceBoundaries = int.Parse(configMap[s_setupSpaceBoundaries]);
                        }
                        if (configMap.ContainsKey(s_setupActivePhase))
                        {
                            configuration.ActivePhaseId = new ElementId(int.Parse(configMap[s_setupActivePhase]));
                        }
                        if (configMap.ContainsKey(s_setupQTO))
                        {
                            configuration.ExportBaseQuantities = bool.Parse(configMap[s_setupQTO]);
                        }
                        if (configMap.ContainsKey(s_setupCurrentView))
                        {
                            configuration.VisibleElementsOfCurrentView = bool.Parse(configMap[s_setupCurrentView]);
                        }
                        if (configMap.ContainsKey(s_splitWallsAndColumns))
                        {
                            configuration.SplitWallsAndColumns = bool.Parse(configMap[s_splitWallsAndColumns]);
                        }
                        if (configMap.ContainsKey(s_setupExport2D))
                        {
                            configuration.Export2DElements = bool.Parse(configMap[s_setupExport2D]);
                        }
                        if (configMap.ContainsKey(s_setupExportRevitProps))
                        {
                            configuration.ExportInternalRevitPropertySets = bool.Parse(configMap[s_setupExportRevitProps]);
                        }
                        if (configMap.ContainsKey(s_setupExportIFCCommonProperty))
                        {
                            configuration.ExportIFCCommonPropertySets = bool.Parse(configMap[s_setupExportIFCCommonProperty]);
                        }
                        if (configMap.ContainsKey(s_setupUse2DForRoomVolume))
                        {
                            configuration.Use2DRoomBoundaryForVolume = bool.Parse(configMap[s_setupUse2DForRoomVolume]);
                        }
                        if (configMap.ContainsKey(s_setupUseFamilyAndTypeName))
                        {
                            configuration.UseFamilyAndTypeNameForReference = bool.Parse(configMap[s_setupUseFamilyAndTypeName]);
                        }
                        if (configMap.ContainsKey(s_setupExportPartsAsBuildingElements))
                        {
                            configuration.ExportPartsAsBuildingElements = bool.Parse(configMap[s_setupExportPartsAsBuildingElements]);
                        }
                        if (configMap.ContainsKey(s_useActiveViewGeometry))
                        {
                            configuration.UseActiveViewGeometry = bool.Parse(configMap[s_useActiveViewGeometry]);
                        }
                        if (configMap.ContainsKey(s_setupExportSpecificSchedules))
                        {
                            configuration.ExportSpecificSchedules = bool.Parse(configMap[s_setupExportSpecificSchedules]);
                        }
                        if (configMap.ContainsKey(s_setupExportBoundingBox))
                        {
                            configuration.ExportBoundingBox = bool.Parse(configMap[s_setupExportBoundingBox]);
                        }
                        if (configMap.ContainsKey(s_setupExportSolidModelRep))
                        {
                            configuration.ExportSolidModelRep = bool.Parse(configMap[s_setupExportSolidModelRep]);
                        }
                        if (configMap.ContainsKey(s_setupExportSchedulesAsPsets))
                        {
                            configuration.ExportSchedulesAsPsets = bool.Parse(configMap[s_setupExportSchedulesAsPsets]);
                        }
                        if (configMap.ContainsKey(s_setupExportUserDefinedPsets))
                        {
                            configuration.ExportUserDefinedPsets = bool.Parse(configMap[s_setupExportUserDefinedPsets]);
                        }
                        if (configMap.ContainsKey(s_setupExportUserDefinedPsetsFileName))
                        {
                            configuration.ExportUserDefinedPsetsFileName = configMap[s_setupExportUserDefinedPsetsFileName];
                        }
                        if (configMap.ContainsKey(s_setupExportUserDefinedParameterMapping))
                        {
                            configuration.ExportUserDefinedParameterMapping = bool.Parse(configMap[s_setupExportUserDefinedParameterMapping]);
                        }
                        if (configMap.ContainsKey(s_setupExportUserDefinedParameterMappingFileName))
                        {
                            configuration.ExportUserDefinedParameterMappingFileName = configMap[s_setupExportUserDefinedParameterMappingFileName];
                        }
                        if (configMap.ContainsKey(s_setupExportLinkedFiles))
                        {
                            configuration.ExportLinkedFiles = bool.Parse(configMap[s_setupExportLinkedFiles]);
                        }
                        if (configMap.ContainsKey(s_setupIncludeSiteElevation))
                        {
                            configuration.IncludeSiteElevation = bool.Parse(configMap[s_setupIncludeSiteElevation]);
                        }
                        if (configMap.ContainsKey(s_setupStoreIFCGUID))
                        {
                            configuration.StoreIFCGUID = bool.Parse(configMap[s_setupStoreIFCGUID]);
                        }
                        if (configMap.ContainsKey(s_setupExportRoomsInView))
                        {
                            configuration.ExportRoomsInView = bool.Parse(configMap[s_setupExportRoomsInView]);
                        }
                        Add(configuration);
                    }

                    return;                     // if finds the config in map schema, return and skip finding the old schema.
                }

                // find the config in old schema.
                if (_schema != null)
                {
                    foreach (DataStorage storedSetup in GetProjectConfigurations(_schema))
                    {
                        Entity configEntity = storedSetup.GetEntity(_schema);
                        IFCExporterConfiguration configuration = IFCExporterConfiguration.CreateDefaultConfiguration();
                        configuration.Name                            = configEntity.Get <String>(s_setupName);
                        configuration.IFCFVersion                     = (IFCVersion)configEntity.Get <int>(s_setupVersion);
                        configuration.IFCFileType                     = (IFCFileFormat)configEntity.Get <int>(s_setupFileFormat);
                        configuration.SpaceBoundaries                 = configEntity.Get <int>(s_setupSpaceBoundaries);
                        configuration.ExportBaseQuantities            = configEntity.Get <bool>(s_setupQTO);
                        configuration.SplitWallsAndColumns            = configEntity.Get <bool>(s_splitWallsAndColumns);
                        configuration.Export2DElements                = configEntity.Get <bool>(s_setupExport2D);
                        configuration.ExportInternalRevitPropertySets = configEntity.Get <bool>(s_setupExportRevitProps);
                        Field fieldIFCCommonPropertySets = _schema.GetField(s_setupExportIFCCommonProperty);
                        if (fieldIFCCommonPropertySets != null)
                        {
                            configuration.ExportIFCCommonPropertySets = configEntity.Get <bool>(s_setupExportIFCCommonProperty);
                        }
                        configuration.Use2DRoomBoundaryForVolume       = configEntity.Get <bool>(s_setupUse2DForRoomVolume);
                        configuration.UseFamilyAndTypeNameForReference = configEntity.Get <bool>(s_setupUseFamilyAndTypeName);
                        Field fieldPartsAsBuildingElements = _schema.GetField(s_setupExportPartsAsBuildingElements);
                        if (fieldPartsAsBuildingElements != null)
                        {
                            configuration.ExportPartsAsBuildingElements = configEntity.Get <bool>(s_setupExportPartsAsBuildingElements);
                        }
                        Field fieldExportBoundingBox = _schema.GetField(s_setupExportBoundingBox);
                        if (fieldExportBoundingBox != null)
                        {
                            configuration.ExportBoundingBox = configEntity.Get <bool>(s_setupExportBoundingBox);
                        }
                        Field fieldExportSolidModelRep = _schema.GetField(s_setupExportSolidModelRep);
                        if (fieldExportSolidModelRep != null)
                        {
                            configuration.ExportSolidModelRep = configEntity.Get <bool>(s_setupExportSolidModelRep);
                        }
                        Field fieldExportSchedulesAsPsets = _schema.GetField(s_setupExportSchedulesAsPsets);
                        if (fieldExportSchedulesAsPsets != null)
                        {
                            configuration.ExportSchedulesAsPsets = configEntity.Get <bool>(s_setupExportSchedulesAsPsets);
                        }
                        Field fieldExportUserDefinedPsets = _schema.GetField(s_setupExportUserDefinedPsets);
                        if (fieldExportUserDefinedPsets != null)
                        {
                            configuration.ExportUserDefinedPsets = configEntity.Get <bool>(s_setupExportUserDefinedPsets);
                        }
                        Field fieldExportUserDefinedPsetsFileName = _schema.GetField(s_setupExportUserDefinedPsetsFileName);
                        if (fieldExportUserDefinedPsetsFileName != null)
                        {
                            configuration.ExportUserDefinedPsetsFileName = configEntity.Get <string>(s_setupExportUserDefinedPsetsFileName);
                        }

                        Field fieldExportUserDefinedParameterMapingTable = _schema.GetField(s_setupExportUserDefinedParameterMapping);
                        if (fieldExportUserDefinedParameterMapingTable != null)
                        {
                            configuration.ExportUserDefinedParameterMapping = configEntity.Get <bool>(s_setupExportUserDefinedParameterMapping);
                        }

                        Field fieldExportUserDefinedParameterMappingFileName = _schema.GetField(s_setupExportUserDefinedParameterMappingFileName);
                        if (fieldExportUserDefinedParameterMappingFileName != null)
                        {
                            configuration.ExportUserDefinedParameterMappingFileName = configEntity.Get <string>(s_setupExportUserDefinedParameterMappingFileName);
                        }

                        Field fieldExportLinkedFiles = _schema.GetField(s_setupExportLinkedFiles);
                        if (fieldExportLinkedFiles != null)
                        {
                            configuration.ExportLinkedFiles = configEntity.Get <bool>(s_setupExportLinkedFiles);
                        }
                        Field fieldIncludeSiteElevation = _schema.GetField(s_setupIncludeSiteElevation);
                        if (fieldIncludeSiteElevation != null)
                        {
                            configuration.IncludeSiteElevation = configEntity.Get <bool>(s_setupIncludeSiteElevation);
                        }
                        Field fieldStoreIFCGUID = _schema.GetField(s_setupStoreIFCGUID);
                        if (fieldStoreIFCGUID != null)
                        {
                            configuration.StoreIFCGUID = configEntity.Get <bool>(s_setupStoreIFCGUID);
                        }
                        Field fieldActivePhase = _schema.GetField(s_setupActivePhase);
                        if (fieldActivePhase != null)
                        {
                            configuration.ActivePhaseId = new ElementId(int.Parse(configEntity.Get <string>(s_setupActivePhase)));
                        }
                        Field fieldExportRoomsInView = _schema.GetField(s_setupExportRoomsInView);
                        if (fieldExportRoomsInView != null)
                        {
                            configuration.ExportRoomsInView = configEntity.Get <bool>(s_setupExportRoomsInView);
                        }
                        Add(configuration);
                    }
                }
            }
            catch (Exception)
            {
                // to avoid fail to show the dialog if any exception throws in reading schema.
            }
        }