Exemplo n.º 1
0
        /// <summary>
        /// Get an IFC Profile Name from the FamilySymbol (the type) name, or from the override parameter of the type "IfcProfileName[Type]"
        /// </summary>
        /// <param name="element">the element (Instance/FamilyInstance or Type/FamilySymbol)</param>
        /// <returns>the profile name</returns>
        public static string GetProfileName(Element element, string originalName = null)
        {
            FamilySymbol fSymb;

            if (element is FamilyInstance)
            {
                fSymb = (element as FamilyInstance).Symbol;
            }
            else
            {
                fSymb = element as FamilySymbol;
            }

            if (fSymb == null)
            {
                return(originalName);
            }

            // Get a profile name. It is by default set to the type (familySymbol) name, but can be overridden by IfcProfileName[Type] shared parameter
            string profileName = fSymb.Name;
            string profile;

            ParameterUtil.GetStringValueFromElement(fSymb, "IfcProfileName[Type]", out profile);
            if (!string.IsNullOrEmpty(profile))
            {
                profileName = profile;
            }

            if (string.IsNullOrEmpty(profileName))
            {
                return(originalName);
            }

            return(profileName);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets override string value from element parameter.
        /// </summary>
        /// <param name="element">
        /// The element.
        /// </param>
        /// <param name="paramName">
        /// The parameter name.
        /// </param>
        /// <param name="originalValue">
        /// The original value.
        /// </param>
        /// <returns>
        /// The string contains the string value.
        /// </returns>
        public static string GetOverrideStringValue(Element element, string paramName, string originalValue)
        {
            //string strValue;
            string paramValue;

            if (element != null)
            {
                if (ParameterUtil.GetStringValueFromElement(element, paramName, out paramValue) != null && !string.IsNullOrEmpty(paramValue))
                {
                    string propertyValue = null;
                    object strValue      = null;
                    ParamExprResolver.CheckForParameterExpr(paramValue, element, paramName, ParamExprResolver.ExpectedValueEnum.STRINGVALUE, out strValue);
                    if (strValue != null && strValue is string)
                    {
                        propertyValue = strValue as string;
                    }
                    else
                    {
                        propertyValue = paramValue; // return the original paramValue
                    }
                    return(propertyValue);
                }
            }

            return(originalValue);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets override string value from element parameter.
        /// </summary>
        /// <param name="element">
        /// The element.
        /// </param>
        /// <param name="paramName">
        /// The parameter name.
        /// </param>
        /// <param name="originalValue">
        /// The original value.
        /// </param>
        /// <returns>
        /// The string contains the string value.
        /// </returns>
        public static string GetOverrideStringValue(Element element, string paramName, string originalValue)
        {
            //string strValue;
            string paramValue;

            if (element != null)
            {
                if (ParameterUtil.GetStringValueFromElement(element, paramName, out paramValue) != null && !string.IsNullOrEmpty(paramValue))
                {
                    string propertyValue  = null;
                    string paramValuetrim = paramValue.Trim();
                    // This is kind of hack to quickly check whether we need to parse the parameter or not by checking that the value is enclosed by "{ }" or "u{ }" for unique value
                    if (((paramValuetrim.Length > 1 && paramValuetrim[0] == '{') || (paramValuetrim.Length > 2 && paramValuetrim[1] == '{')) && (paramValuetrim[paramValuetrim.Length - 1] == '}'))
                    {
                        ParamExprResolver pResv = new ParamExprResolver(element, paramName, paramValuetrim);
                        propertyValue = pResv.GetStringValue();
                        if (string.IsNullOrEmpty(propertyValue))
                        {
                            propertyValue = paramValue; // return the original paramValue
                        }
                    }
                    else
                    {
                        propertyValue = paramValue; // return the original paramValue
                    }
                    //return paramValue;
                    return(propertyValue);
                }
            }

            return(originalValue);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates a Project, Site, or Building GUID.  If a shared parameter is set with a valid IFC GUID value,
        /// that value will override the default one.
        /// </summary>
        /// <param name="document">The document.</param>
        /// <param name="guidType">The GUID being created.</param>
        /// <returns>The IFC GUID value.</returns>
        /// <remarks>For Sites, the user should only use this routine if there is no Site element in the file.  Otherwise, they
        /// should use CreateSiteGUID below, which takes an Element pointer.</remarks>
        static public string CreateProjectLevelGUID(Document document, IFCProjectLevelGUIDType guidType)
        {
            string      parameterName = "Ifc" + guidType.ToString() + " GUID";
            ProjectInfo projectInfo   = document.ProjectInformation;

            BuiltInParameter parameterId = BuiltInParameter.INVALID;

            switch (guidType)
            {
            case IFCProjectLevelGUIDType.Building:
                parameterId = BuiltInParameter.IFC_BUILDING_GUID;
                break;

            case IFCProjectLevelGUIDType.Project:
                parameterId = BuiltInParameter.IFC_PROJECT_GUID;
                break;

            case IFCProjectLevelGUIDType.Site:
                parameterId = BuiltInParameter.IFC_SITE_GUID;
                break;

            default:
                // This should eventually log an error.
                return(null);
            }

            if (projectInfo != null)
            {
                string paramValue = null;
                ParameterUtil.GetStringValueFromElement(projectInfo, parameterName, out paramValue);
                if (!IsValidIFCGUID(paramValue) && parameterId != BuiltInParameter.INVALID)
                {
                    ParameterUtil.GetStringValueFromElement(projectInfo, parameterId, out paramValue);
                }

                if (IsValidIFCGUID(paramValue))
                {
                    return(paramValue);
                }
            }

            // Only for 2022
            //ElementId projectLevelElementId = new ElementId((int)guidType);
            //System.Guid guid = ExportUtils.GetExportId(document, projectLevelElementId);
            //string ifcGUID = ConvertToIFCGuid(guid);
            string ifcGUID = ExporterIFCUtils.CreateProjectLevelGUID(document, guidType);

            if ((projectInfo != null) && ExporterCacheManager.ExportOptionsCache.GUIDOptions.StoreIFCGUID)
            {
                if (parameterId != BuiltInParameter.INVALID)
                {
                    ExporterCacheManager.GUIDsToStoreCache[new KeyValuePair <ElementId, BuiltInParameter>(projectInfo.Id, parameterId)] = ifcGUID;
                }
            }
            return(ifcGUID);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Get override containment value through a parameter "IfcSpatialContainer" or "OverrideElementContainer". Value can be "IFCSITE", "IFCBUILDING", or the appropriate Level name
        /// </summary>
        /// <param name="element">the element</param>
        /// <param name="overrideContainerHnd">the override container Handle</param>
        /// <returns>true if there is override</returns>
        public static ElementId OverrideContainmentParameter(ExporterIFC exporterIFC, Element element, out IFCAnyHandle overrideContainerHnd)
        {
            ElementId containerElemId = ElementId.InvalidElementId;

            // Special case whether an object should be assigned to the Site or Building container
            overrideContainerHnd = null;
            string containerOverrideName = null;

            if (ParameterUtil.GetStringValueFromElement(element, "OverrideElementContainer", out containerOverrideName) == null)
            {
                ParameterUtil.GetStringValueFromElement(element, "IfcSpatialContainer", out containerOverrideName);
            }
            if (!string.IsNullOrEmpty(containerOverrideName))
            {
                if (containerOverrideName.Equals("IFCSITE", StringComparison.CurrentCultureIgnoreCase))
                {
                    overrideContainerHnd = ExporterCacheManager.SiteHandle;
                    return(containerElemId);
                }
                else if (containerOverrideName.Equals("IFCBUILDING", StringComparison.CurrentCultureIgnoreCase))
                {
                    overrideContainerHnd = ExporterCacheManager.BuildingHandle;
                    return(containerElemId);
                }

                // Find Level that is designated as the override by iterating through all the Levels for the name match
                FilteredElementCollector collector  = new FilteredElementCollector(element.Document);
                ICollection <Element>    collection = collector.OfClass(typeof(Level)).ToElements();
                foreach (Element level in collection)
                {
                    if (level.Name.Equals(containerOverrideName, StringComparison.CurrentCultureIgnoreCase))
                    {
                        containerElemId = level.Id;
                        break;
                    }
                }
                if (containerElemId != ElementId.InvalidElementId)
                {
                    IFCLevelInfo levelInfo = ExporterCacheManager.LevelInfoCache.GetLevelInfo(exporterIFC, containerElemId);
                    if (levelInfo != null)
                    {
                        overrideContainerHnd = levelInfo.GetBuildingStorey();
                    }
                    if (overrideContainerHnd != null)
                    {
                        return(containerElemId);
                    }
                }
            }

            return(containerElemId);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Creates a Site GUID for a Site element.  If "IfcSite GUID" is set to a valid IFC GUID
        /// in the site element, that value will override any value stored in ProjectInformation.
        /// </summary>
        /// <param name="document">The document pointer.</param>
        /// <param name="element">The Site element.</param>
        /// <returns>The GUID as a string.</returns>
        static public string CreateSiteGUID(Document document, Element element)
        {
            if (element != null)
            {
                ParameterUtil.GetStringValueFromElement(element, "IfcSiteGUID", out string paramValue);
                if (IsValidIFCGUID(paramValue))
                {
                    return(paramValue);
                }
            }

            return(CreateProjectLevelGUID(document, ProjectLevelGUIDType.Site));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Creates a Site GUID for a Site element.  If "IfcSite GUID" is set to a valid IFC GUID in Project Information, that value will
        /// override the default GUID generation for the Site element.
        /// </summary>
        /// <param name="document">The document pointer.</param>
        /// <param name="element">The Site element.</param>
        /// <returns></returns>
        static public string CreateSiteGUID(Document document, Element element)
        {
            ProjectInfo projectInfo = document.ProjectInformation;

            if (projectInfo != null)
            {
                string paramValue = null;
                ParameterUtil.GetStringValueFromElement(projectInfo.Id, "IfcSiteGUID", out paramValue);
                if ((paramValue != null) && (IsValidIFCGUID(paramValue)))
                {
                    return(paramValue);
                }
            }

            return(CreateGUID(element));
        }
Exemplo n.º 8
0
        /// <summary>
        /// Creates a Project, Site, or Building GUID.  If a shared parameter is set with a valid IFC GUID value,
        /// that value will override the default one.
        /// </summary>
        /// <param name="document">The document.</param>
        /// <param name="guidType">The GUID being created.</param>
        /// <returns>The IFC GUID value.</returns>
        /// <remarks>For Sites, the user should only use this routine if there is no Site element in the file.  Otherwise, they
        /// should use CreateSiteGUID below, which takes an Element pointer.</remarks>
        static public string CreateProjectLevelGUID(Document document, IFCProjectLevelGUIDType guidType)
        {
            string      parameterName = "Ifc" + guidType.ToString() + " GUID";
            ProjectInfo projectInfo   = document.ProjectInformation;

            BuiltInParameter parameterId = BuiltInParameter.INVALID;

            switch (guidType)
            {
            case IFCProjectLevelGUIDType.Building:
                parameterId = BuiltInParameter.IFC_BUILDING_GUID;
                break;

            case IFCProjectLevelGUIDType.Project:
                parameterId = BuiltInParameter.IFC_PROJECT_GUID;
                break;

            case IFCProjectLevelGUIDType.Site:
                parameterId = BuiltInParameter.IFC_SITE_GUID;
                break;
            }

            if (projectInfo != null)
            {
                string paramValue = null;
                ParameterUtil.GetStringValueFromElement(projectInfo, parameterName, out paramValue);
                if ((paramValue != null) && (IsValidIFCGUID(paramValue)))
                {
                    return(paramValue);
                }
                if (parameterId != BuiltInParameter.INVALID && ParameterUtil.GetStringValueFromElement(projectInfo, parameterId, out paramValue) != null)
                {
                    return(paramValue);
                }
            }
            string guid = ExporterIFCUtils.CreateProjectLevelGUID(document, guidType);

            if ((projectInfo != null) && ExporterCacheManager.ExportOptionsCache.GUIDOptions.StoreIFCGUID)
            {
                if (parameterId != BuiltInParameter.INVALID)
                {
                    ExporterCacheManager.GUIDsToStoreCache[new KeyValuePair <Element, BuiltInParameter>(projectInfo, parameterId)] = guid;
                }
            }
            return(guid);
        }
Exemplo n.º 9
0
        static private string CreateGUIDBase(Element element, BuiltInParameter parameterName, out bool shouldStore)
        {
            shouldStore = false;
            string ifcGUID = null;

            if (ExporterCacheManager.ExportOptionsCache.GUIDOptions.AllowGUIDParameterOverride)
            {
                ParameterUtil.GetStringValueFromElement(element, parameterName, out ifcGUID);
            }
            if (!IsValidIFCGUID(ifcGUID))
            {
                System.Guid guid = ExportUtils.GetExportId(element.Document, element.Id);
                ifcGUID     = ConvertToIFCGuid(guid);
                shouldStore = true;
            }

            return(ifcGUID);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Gets override string value from element parameter.
        /// </summary>
        /// <param name="element">
        /// The element.
        /// </param>
        /// <param name="paramName">
        /// The parameter name.
        /// </param>
        /// <param name="originalValue">
        /// The original value.
        /// </param>
        /// <returns>
        /// The string contains the string value.
        /// </returns>
        public static string GetOverrideStringValue(Element element, string paramName, string originalValue)
        {
            string strValue;

            // get the IFC Name Override
            if (element != null)
            {
                if (ParameterUtil.GetStringValueFromElement(element.Id, paramName, out strValue) != null)
                {
                    if (!String.IsNullOrWhiteSpace(strValue))
                    {
                        return(strValue);
                    }
                }
            }

            return(originalValue);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Gets override string value from element parameter.
        /// </summary>
        /// <param name="element">
        /// The element.
        /// </param>
        /// <param name="paramName">
        /// The parameter name.
        /// </param>
        /// <param name="originalValue">
        /// The original value.
        /// </param>
        /// <returns>
        /// The string contains the string value.
        /// </returns>
        public static string GetOverrideStringValue(Element element, string paramName, string originalValue)
        {
            string strValue;

            if (element != null)
            {
                if (ParameterUtil.GetStringValueFromElement(element.Id, paramName, out strValue) != null)
                {
                    // Returns a string value from the parameter of an element.
                    // If the string is empty, it returns the originalValue.
                    if (!String.IsNullOrWhiteSpace(strValue))
                    {
                        return(strValue);
                    }
                }
            }

            return(originalValue);
        }
Exemplo n.º 12
0
        static private string CreateGUIDBase(Element element, BuiltInParameter parameterName, out bool shouldStore)
        {
            string ifcGUID = null;

            shouldStore = CanStoreGUID(element);

            // Avoid getting into an object if the object is part of the Group. It may cause regrenerate that invalidate other ElementIds
            if (shouldStore && ExporterCacheManager.ExportOptionsCache.GUIDOptions.AllowGUIDParameterOverride)
            {
                ParameterUtil.GetStringValueFromElement(element, parameterName, out ifcGUID);
            }

            if (!IsValidIFCGUID(ifcGUID))
            {
                ifcGUID = CreateSimpleGUID(element);
            }

            return(ifcGUID);
        }
Exemplo n.º 13
0
        private void CalculateDoorWindowInformation(ExporterIFC exporterIFC, FamilyInstance famInst,
                                                    ElementId overrideLevelId, Transform trf)
        {
            IFCFile file = exporterIFC.GetFile();

            if (ExportingDoor)
            {
                string doorOperationType = null;

                Element doorType = famInst.Document.GetElement(famInst.GetTypeId());
                if (doorType != null)
                {
                    // Look at the "Operation" override first, then the built-in parameter.
                    ParameterUtil.GetStringValueFromElementOrSymbol(doorType, "Operation", out doorOperationType);
                    if (!string.IsNullOrWhiteSpace(doorOperationType))
                    {
                        ParameterUtil.GetStringValueFromElement(doorType, BuiltInParameter.DOOR_OPERATION_TYPE, out doorOperationType);
                    }
                }

                DoorOperationTypeString = "NOTDEFINED";
                if (!string.IsNullOrWhiteSpace(doorOperationType))
                {
                    Type enumType = null;
                    if (ExporterCacheManager.ExportOptionsCache.ExportAs4)
                    {
                        enumType = typeof(Toolkit.IFC4.IFCDoorStyleOperation);
                    }
                    else
                    {
                        enumType = typeof(Toolkit.IFCDoorStyleOperation);
                    }

                    foreach (Enum ifcDoorStyleOperation in Enum.GetValues(enumType))
                    {
                        string enumAsString = ifcDoorStyleOperation.ToString();
                        if (NamingUtil.IsEqualIgnoringCaseSpacesAndUnderscores(enumAsString, doorOperationType))
                        {
                            DoorOperationTypeString = enumAsString;
                            break;
                        }
                    }
                }

                if (DoorOperationTypeString == "NOTDEFINED")
                {
                    // We are going to try to guess the hinge placement.
                    DoorOperationTypeString = CalculateDoorOperationStyle(famInst);
                }

                if (FlippedX ^ FlippedY)
                {
                    DoorOperationTypeString = ReverseDoorStyleOperation(DoorOperationTypeString);
                }

                if (String.Compare(DoorOperationTypeString, "USERDEFINED", true) == 0)
                {
                    string userDefinedOperationType;
                    ParameterUtil.GetStringValueFromElementOrSymbol(doorType, "UserDefinedOperationType", out userDefinedOperationType);
                    if (!string.IsNullOrEmpty(userDefinedOperationType))
                    {
                        UserDefinedOperationType = userDefinedOperationType;
                    }
                    else
                    {
                        DoorOperationTypeString = "NOTDEFINED";   //re-set to NotDefined if operation type is set to UserDefined but the userDefinedOperationType parameter is empty!
                    }
                }
            }

            if (HasRealWallHost)
            {
                // do hingeside calculation
                Wall wall = HostObject as Wall;
                PosHingeSide = true;

                BoundingBoxXYZ  famBBox     = null;
                Options         options     = GeometryUtil.GetIFCExportGeometryOptions();
                GeometryElement geomElement = famInst.GetOriginalGeometry(options);
                if (geomElement != null)
                {
                    famBBox = geomElement.GetBoundingBox();
                }

                if (famBBox != null)
                {
                    XYZ bboxCtr = trf.OfPoint((famBBox.Min + famBBox.Max) / 2.0);

                    Curve curve = WallExporter.GetWallAxis(wall);

                    XYZ wallZDir = WallExporter.GetWallHeightDirection(wall);

                    // famInst.HostParameter will fail if FamilyPlacementType is WorkPlaneBased, regardless of whether or not the reported host is a Wall.
                    // In this case, just use the start parameter of the curve.
                    bool   hasHostParameter = famInst.Symbol.Family.FamilyPlacementType != FamilyPlacementType.WorkPlaneBased;
                    double param            = hasHostParameter ? famInst.HostParameter : curve.GetEndParameter(0);

                    Transform wallTrf  = curve.ComputeDerivatives(param, false);
                    XYZ       wallOrig = wallTrf.Origin;
                    XYZ       wallXDir = wallTrf.BasisX;
                    XYZ       wallYDir = wallZDir.CrossProduct(wallXDir);

                    double eps = MathUtil.Eps();

                    bboxCtr     -= wallOrig;
                    PosHingeSide = (bboxCtr.DotProduct(wallYDir) > -eps);

                    XYZ famInstYDir = trf.BasisY;
                    FlippedSymbol = (PosHingeSide != (wallYDir.DotProduct(famInstYDir) > -eps));
                }
            }
        }