Beispiel #1
0
        /// <summary>
        /// Creates or populates Revit element params based on the information contained in this class.
        /// </summary>
        /// <param name="doc">The document.</param>
        /// <param name="element">The element.</param>
        protected override void CreateParametersInternal(Document doc, Element element)
        {
            base.CreateParametersInternal(doc, element);

            if (element != null)
            {
                Category category = IFCPropertySet.GetCategoryForParameterIfValid(element, Id);

                // Set "Tag" parameter.
                string ifcTag = Tag;
                if (!string.IsNullOrWhiteSpace(ifcTag))
                {
                    IFCPropertySet.AddParameterString(doc, element, category, "IfcTag", ifcTag, Id);
                }

                IFCFeatureElementSubtraction ifcFeatureElementSubtraction = FillsOpening;
                if (ifcFeatureElementSubtraction != null)
                {
                    IFCElement ifcElement = ifcFeatureElementSubtraction.VoidsElement;
                    if (ifcElement != null)
                    {
                        string ifcContainerName = ifcElement.Name;
                        IFCPropertySet.AddParameterString(doc, element, category, "IfcContainedInHost", ifcContainerName, Id);
                    }
                }

                // Create two parameters for each port: one for name, and one for GUID.
                // Note that Ports will never be null, as it is initialized the first time it is accessed.
                int numPorts = 0;
                foreach (IFCPort port in Ports)
                {
                    string name = port.Name;
                    string guid = port.GlobalId;

                    if (!string.IsNullOrWhiteSpace(name))
                    {
                        string parameterName = "IfcElement HasPorts Name " + ((numPorts == 0) ? "" : (numPorts + 1).ToString());
                        IFCPropertySet.AddParameterString(doc, element, category, parameterName, name, Id);
                    }

                    if (!string.IsNullOrWhiteSpace(guid))
                    {
                        string parameterName = "IfcElement HasPorts IfcGUID " + ((numPorts == 0) ? "" : (numPorts + 1).ToString());
                        IFCPropertySet.AddParameterString(doc, element, category, parameterName, guid, Id);
                    }

                    numPorts++;
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Creates or populates Revit element params based on the information contained in this class.
        /// </summary>
        /// <param name="doc">The document.</param>
        /// <param name="element">The element.</param>
        protected override void CreateParametersInternal(Document doc, Element element)
        {
            base.CreateParametersInternal(doc, element);

            if (element != null)
            {
                // Set "Tag" parameter.
                string ifcTag = Tag;
                if (!string.IsNullOrWhiteSpace(ifcTag))
                {
                    IFCPropertySet.AddParameterString(doc, element, "IfcTag", ifcTag, Id);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Creates or populates Revit element params based on the information contained in this class.
        /// </summary>
        /// <param name="doc">The document.</param>
        /// <param name="element">The element.</param>
        protected override void CreateParametersInternal(Document doc, Element element)
        {
            base.CreateParametersInternal(doc, element);

            if (element != null)
            {
                // Set "ObjectTypeOverride" parameter.
                string objectTypeOverride = ObjectType;
                if (!string.IsNullOrWhiteSpace(objectTypeOverride))
                {
                    IFCPropertySet.AddParameterString(doc, element, "ObjectTypeOverride", objectTypeOverride, Id);
                }
            }
        }
        /// <summary>
        /// Creates or populates Revit element params based on the information contained in this class.
        /// </summary>
        /// <param name="doc">The document.</param>
        /// <param name="element">The element.</param>
        protected override void CreateParametersInternal(Document doc, Element element)
        {
            base.CreateParametersInternal(doc, element);

            // TODO: Set the value in ProjectInfo if element is not created.
            if (element != null)
            {
                // Set "ObjectTypeOverride" parameter.
                string longName = LongName;
                if (!string.IsNullOrWhiteSpace(longName))
                {
                    IFCPropertySet.AddParameterString(doc, element, "LongNameOverride", longName, Id);
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// Creates or populates Revit element params based on the information contained in this class.
        /// </summary>
        /// <param name="doc">The document.</param>
        /// <param name="element">The element.</param>
        protected override void CreateParametersInternal(Document doc, Element element)
        {
            base.CreateParametersInternal(doc, element);

            if (element != null)
            {
                Category category = IFCPropertySet.GetCategoryForParameterIfValid(element, Id);
                if (category != null)
                {
                    Importer.TheProcessor.SetStringParameter(element, Id, BuiltInParameter.DOOR_OPERATION_TYPE, OperationType.ToString(), false);
                    Importer.TheProcessor.SetStringParameter(element, Id, BuiltInParameter.DOOR_CONSTRUCTION_TYPE, ConstructionType.ToString(), false);

                    IFCPropertySet.AddParameterString(doc, element, category, this, "IfcOperationType", OperationType.ToString(), Id);
                    IFCPropertySet.AddParameterString(doc, element, category, this, "IfcConstructionType", ConstructionType.ToString(), Id);
                }
            }
        }
Beispiel #6
0
        /// <summary>
        /// Creates or populates Revit element params based on the information contained in this class.
        /// </summary>
        /// <param name="doc">The document.</param>
        /// <param name="element">The element.</param>
        protected override void CreateParametersInternal(Document doc, Element element)
        {
            base.CreateParametersInternal(doc, element);
            string parameterName = "LandTitleNumber";

            if (element == null)
            {
                element       = doc.ProjectInformation;
                parameterName = "Site " + parameterName;
            }

            if (element != null)
            {
                string landTitleNumber = LandTitleNumber;
                if (!string.IsNullOrWhiteSpace(landTitleNumber))
                {
                    IFCPropertySet.AddParameterString(doc, element, parameterName, landTitleNumber, Id);
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// Creates or populates Revit element params based on the information contained in this class.
        /// </summary>
        /// <param name="doc">The document.</param>
        /// <param name="element">The element.</param>
        protected override void CreateParametersInternal(Document doc, Element element)
        {
            base.CreateParametersInternal(doc, element);
            string parameterName = "LandTitleNumber";

            // TODO: move this to new shared parameter names override function.
            if (element is ProjectInfo)
            {
                parameterName = "IfcSite " + parameterName;
            }

            if (element != null)
            {
                string landTitleNumber = LandTitleNumber;
                if (!string.IsNullOrWhiteSpace(landTitleNumber))
                {
                    IFCPropertySet.AddParameterString(doc, element, parameterName, landTitleNumber, Id);
                }
            }
        }
Beispiel #8
0
        /// <summary>
        /// Creates or populates Revit element params based on the information contained in this class.
        /// </summary>
        /// <param name="doc">The document.</param>
        /// <param name="element">The element.</param>
        protected override void CreateParametersInternal(Document doc, Element element)
        {
            base.CreateParametersInternal(doc, element);

            if (element != null)
            {
                Category category = IFCPropertySet.GetCategoryForParameterIfValid(element, Id);

                // Set "IfcPresentationLayer" parameter.
                string ifcPresentationLayer = null;
                foreach (string currLayer in PresentationLayerNames)
                {
                    if (string.IsNullOrWhiteSpace(currLayer))
                    {
                        continue;
                    }

                    if (ifcPresentationLayer == null)
                    {
                        ifcPresentationLayer = currLayer;
                    }
                    else
                    {
                        ifcPresentationLayer += "; " + currLayer;
                    }
                }

                if (ifcPresentationLayer != null)
                {
                    IFCPropertySet.AddParameterString(doc, element, category, this, "IfcPresentationLayer", ifcPresentationLayer, Id);
                }

                // Set the container name of the element.
                string containerName = ContainingStructure?.Name;
                if (containerName != null)
                {
                    IFCPropertySet.AddParameterString(doc, element, category, this, "IfcSpatialContainer", containerName, Id);
                    IFCPropertySet.AddParameterString(doc, element, category, this, "IfcSpatialContainer GUID", ContainingStructure.GlobalId, Id);
                }
            }
        }
        /// <summary>
        /// Creates or populates Revit element params based on the information contained in this class.
        /// </summary>
        /// <param name="doc">The document.</param>
        /// <param name="element">The element.</param>
        protected override void CreateParametersInternal(Document doc, Element element)
        {
            base.CreateParametersInternal(doc, element);

            if (element != null)
            {
                Parameter operationTypeParameter = element.get_Parameter(BuiltInParameter.DOOR_OPERATION_TYPE);
                if (operationTypeParameter != null)
                {
                    operationTypeParameter.Set(OperationType.ToString());
                }
                IFCPropertySet.AddParameterString(doc, element, "IfcOperationType", OperationType.ToString(), Id);

                Parameter constructionTypeParameter = element.get_Parameter(BuiltInParameter.DOOR_CONSTRUCTION_TYPE);
                if (constructionTypeParameter != null)
                {
                    constructionTypeParameter.Set(ConstructionType.ToString());
                }
                IFCPropertySet.AddParameterString(doc, element, "IfcConstructionType", ConstructionType.ToString(), Id);
            }
        }
        /// <summary>
        /// Creates or populates Revit element params based on the information contained in this class.
        /// </summary>
        /// <param name="doc">The document.</param>
        /// <param name="element">The element.</param>
        protected override void CreateParametersInternal(Document doc, Element element)
        {
            base.CreateParametersInternal(doc, element);


            if (element != null)
            {
                // Set "ObjectTypeOverride" parameter.
                string longName = LongName;
                if (!string.IsNullOrWhiteSpace(longName))
                {
                    string parameterName = "LongNameOverride";
                    if (element is ProjectInfo)
                    {
                        parameterName = EntityType.ToString() + " " + parameterName;
                    }

                    IFCPropertySet.AddParameterString(doc, element, parameterName, longName, Id);
                }
            }
        }
Beispiel #11
0
        protected virtual void CreateParametersInternal(Document doc, Element element)
        {
            if (element != null)
            {
                // Set the element name.
                SetName(doc, element);

                // Set the element description.
                SetDescription(doc, element);

                // The list of materials.
                setMaterialParameter(doc, element);

                // Set the element GUID.
                bool             elementIsType = (element is ElementType);
                BuiltInParameter ifcGUIDId     = elementIsType ? BuiltInParameter.IFC_TYPE_GUID : BuiltInParameter.IFC_GUID;
                Parameter        guidParam     = element.get_Parameter(ifcGUIDId);
                if (guidParam != null && !guidParam.IsReadOnly)
                {
                    guidParam.Set(GlobalId);
                }
                else
                {
                    ExporterIFCUtils.AddValueString(element, new ElementId(ifcGUIDId), GlobalId);
                }

                // Set the "IfcExportAs" parameter.
                string ifcExportAs = IFCCategoryUtil.GetCustomCategoryName(this);
                if (!string.IsNullOrWhiteSpace(ifcExportAs))
                {
                    IFCPropertySet.AddParameterString(doc, element, "IfcExportAs", ifcExportAs, Id);
                }

                // Add property set-based parameters.
                // We are going to create this "fake" parameter so that we can filter elements in schedules based on their property sets.
                string propertySetListName = elementIsType ? "Type IfcPropertySetList" : "IfcPropertySetList";
                IFCPropertySet.AddParameterString(doc, element, propertySetListName, "", Id);
            }
        }
Beispiel #12
0
        /// <summary>
        /// Add a parameter "IfcMaterial" to an element containing the name(s) of the materials of the generating entity.
        /// </summary>
        /// <param name="doc">The document.</param>
        /// <param name="element">The created element.</param>
        /// <remarks>Note that this field contains the names of the materials, and as such is not parametric in any way.</remarks>
        private void SetMaterialParameter(Document doc, Element element)
        {
            string materialNames = null;

            IList <string> materialsAndThickness = GetMaterialsNamesAndThicknesses();

            foreach (string val in materialsAndThickness)
            {
                if (materialNames == null)
                {
                    materialNames = val;
                }
                else
                {
                    materialNames += ";" + val;
                }
            }
            if (materialNames != null)
            {
                IFCPropertySet.AddParameterString(doc, element, this, IFCSharedParameters.IfcMaterial, materialNames, Id);
            }
        }
Beispiel #13
0
        /// <summary>
        /// Creates or populates Revit element params based on the information contained in this class.
        /// </summary>
        /// <param name="doc">The document.</param>
        /// <param name="element">The element.</param>
        protected override void CreateParametersInternal(Document doc, Element element)
        {
            base.CreateParametersInternal(doc, element);

            if (element != null)
            {
                // Set "IfcPresentationLayer" parameter.
                string ifcPresentationLayer = null;
                foreach (string currLayer in PresentationLayerNames)
                {
                    if (string.IsNullOrWhiteSpace(currLayer))
                    {
                        continue;
                    }

                    if (ifcPresentationLayer == null)
                    {
                        ifcPresentationLayer = currLayer;
                    }
                    else
                    {
                        ifcPresentationLayer += "; " + currLayer;
                    }
                }

                if (ifcPresentationLayer != null)
                {
                    IFCPropertySet.AddParameterString(doc, element, "IfcPresentationLayer", ifcPresentationLayer, Id);
                }

                // Set the container name of the element.
                string containerName = (ContainingStructure != null) ? ContainingStructure.Name : null;
                if (containerName != null)
                {
                    IFCPropertySet.AddParameterString(doc, element, "IfcSpatialContainer", containerName, Id);
                }
            }
        }
Beispiel #14
0
        /// <summary>
        /// Creates or populates Revit element params based on the information contained in this class.
        /// </summary>
        /// <param name="doc">The document.</param>
        /// <param name="element">The element.</param>
        protected override void CreateParametersInternal(Document doc, Element element)
        {
            base.CreateParametersInternal(doc, element);

            if (element != null)
            {
                Category category = IFCPropertySet.GetCategoryForParameterIfValid(element, Id);

                // Set "Tag" parameter.
                string ifcTag = Tag;
                if (!string.IsNullOrWhiteSpace(ifcTag))
                {
                    IFCPropertySet.AddParameterString(doc, element, category, this, "IfcTag", ifcTag, Id);
                }

                // Set "ProxyType" parameter.
                string ifcProxyType = ProxyType;
                if (!string.IsNullOrWhiteSpace(ifcProxyType))
                {
                    IFCPropertySet.AddParameterString(doc, element, category, this, "IfcProxyType", ifcProxyType, Id);
                }
            }
        }
        /// <summary>
        /// Add parameter "IfcSystem" to an element containing the name(s) of the system(s) of the generating entity.
        /// </summary>
        /// <param name="doc">The document.</param>
        /// <param name="element">The created element.</param>
        /// <param name="category">The element's category.</param>
        /// <remarks>Note that this field contains the names of the systems, and as such is not parametric in any way.</remarks>
        private void SetSystemParameter(Document doc, Element element, Category category)
        {
            if (category == null)
            {
                return;
            }

            string systemNames = null;

            foreach (IFCGroup assignmentGroup in AssignmentGroups)
            {
                if (!(assignmentGroup is IFCSystem))
                {
                    continue;
                }

                string name = assignmentGroup.Name;
                if (string.IsNullOrWhiteSpace(name))
                {
                    continue;
                }

                if (systemNames == null)
                {
                    systemNames = name;
                }
                else
                {
                    systemNames += ";" + name;
                }
            }

            if (systemNames != null)
            {
                IFCPropertySet.AddParameterString(doc, element, category, this, "IfcSystem", systemNames, Id);
            }
        }
Beispiel #16
0
        /// <summary>
        /// Set the Element.Name property if possible, and add an "IfcName" parameter to an element containing the original name of the generating entity.
        /// </summary>
        /// <param name="doc">The document.</param>
        /// <param name="element">The created element.</param>
        private void SetName(Document doc, Element element)
        {
            string revitName = GetName(null);

            if (!string.IsNullOrWhiteSpace(revitName))
            {
                try
                {
                    if (CanSetRevitName(element))
                    {
                        element.Name = revitName;
                    }
                }
                catch
                {
                }
            }

            string name = string.IsNullOrWhiteSpace(Name) ? "" : Name;

            // 2015: Revit links don't show the name of a selected item inside the link.
            // 2015: DirectShapes don't have a built-in "Name" parameter.
            IFCPropertySet.AddParameterString(doc, element, "IfcName", Name, Id);
        }
Beispiel #17
0
        private static void UpdateDocumentFileMetrics(Document doc, string ifcFileName)
        {
            FileInfo infoIFC = null;

            try
            {
                infoIFC = new FileInfo(ifcFileName);
            }
            catch
            {
                return;
            }

            ProjectInfo projInfo = doc.ProjectInformation;

            if (projInfo == null)
            {
                return;
            }

            long  ifcFileLength = infoIFC.Length;
            Int64 ticks         = infoIFC.LastWriteTimeUtc.Ticks;

            // If we find our parameters, but they are the wrong type, return.
            Parameter originalFileName = projInfo.LookupParameter("Original IFC File Name");

            if (originalFileName != null && originalFileName.StorageType != StorageType.String)
            {
                return;
            }

            Parameter originalFileSizeParam = projInfo.LookupParameter("Original IFC File Size");

            if (originalFileSizeParam != null && originalFileSizeParam.StorageType != StorageType.String)
            {
                return;
            }

            Parameter originalTimeStampParam = projInfo.LookupParameter("Revit File Last Updated");

            if (originalTimeStampParam != null && originalTimeStampParam.StorageType != StorageType.String)
            {
                return;
            }

            Parameter originalImporterVersion = projInfo.LookupParameter("Revit Importer Version");

            if (originalTimeStampParam != null && originalTimeStampParam.StorageType != StorageType.String)
            {
                return;
            }

            if (originalFileName != null)
            {
                originalFileName.Set(ifcFileName);
            }
            else
            {
                IFCPropertySet.AddParameterString(doc, projInfo, "Original IFC File Name", ifcFileName, -1);
            }

            if (originalFileSizeParam != null)
            {
                originalFileSizeParam.Set(ifcFileLength.ToString());
            }
            else
            {
                IFCPropertySet.AddParameterString(doc, projInfo, "Original IFC File Size", ifcFileLength.ToString(), -1);
            }

            if (originalTimeStampParam != null)
            {
                originalTimeStampParam.Set(ticks.ToString());
            }
            else
            {
                IFCPropertySet.AddParameterString(doc, projInfo, "Revit File Last Updated", ticks.ToString(), -1);
            }

            if (originalImporterVersion != null)
            {
                originalImporterVersion.Set(IFCImportOptions.ImporterVersion);
            }
            else
            {
                IFCPropertySet.AddParameterString(doc, projInfo, "Revit Importer Version", IFCImportOptions.ImporterVersion, -1);
            }
        }
Beispiel #18
0
        /// <summary>
        /// Create a property for a given element.
        /// </summary>
        /// <param name="doc">The document.</param>
        /// <param name="element">The element being created.</param>
        /// <param name="category">The category of the element being created.</param>
        /// <param name="parameterMap">The parameters of the element.  Cached for performance.</param>
        /// <param name="propertySetName">The name of the containing property set.</param>
        /// <param name="createdParameters">The names of the created parameters.</param>
        public void Create(Document doc, Element element, Category category, IFCObjectDefinition objDef, IFCParameterSetByGroup parameterGroupMap, string propertySetName, ISet <string> createdParameters)
        {
            // Try to get the single value from the property.  If we can't get a single value, get it as a string.
            IFCPropertyValue propertyValueToUse = null;

            if (this is IFCSimpleProperty)
            {
                IFCSimpleProperty        simpleProperty = this as IFCSimpleProperty;
                IList <IFCPropertyValue> propertyValues = simpleProperty.IFCPropertyValues;
                if (propertyValues != null && propertyValues.Count == 1)
                {
                    // If the value isn't set, skip it.  We won't warn.
                    if (!propertyValues[0].HasValue())
                    {
                        return;
                    }

                    propertyValueToUse = propertyValues[0];
                }
            }

            IFCDataPrimitiveType dataType    = IFCDataPrimitiveType.Unknown;
            ForgeTypeId          specTypeId  = new ForgeTypeId();
            ForgeTypeId          unitsTypeId = null;

            bool?      boolValueToUse      = null;
            IFCLogical?logicalValueToUse   = null;
            int?       intValueToUse       = null;
            double?    doubleValueToUse    = null;
            ElementId  elementIdValueToUse = null;
            string     stringValueToUse    = null;

            if (propertyValueToUse == null)
            {
                string propertyValueAsString = PropertyValueAsString();
                if (propertyValueAsString == null)
                {
                    Importer.TheLog.LogError(Id, "Couldn't create parameter: " + Name, false);
                    return;
                }

                dataType         = IFCDataPrimitiveType.String;
                stringValueToUse = propertyValueAsString;
            }
            else
            {
                dataType = propertyValueToUse.Value.PrimitiveType;
                if (dataType == IFCDataPrimitiveType.Instance)
                {
                    IFCAnyHandle propertyValueHandle = propertyValueToUse.Value.AsInstance();
                    ElementId    propertyValueAsId   = IFCObjectReferenceSelect.ToElementId(propertyValueHandle);
                    if (propertyValueAsId != ElementId.InvalidElementId)
                    {
                        elementIdValueToUse = propertyValueAsId;
                    }
                    else
                    {
                        stringValueToUse = IFCObjectReferenceSelect.ToString(propertyValueHandle);
                        dataType         = IFCDataPrimitiveType.String;
                    }
                }
                else
                {
                    switch (dataType)
                    {
                    case IFCDataPrimitiveType.String:
                    case IFCDataPrimitiveType.Enumeration:
                    case IFCDataPrimitiveType.Binary:
                        stringValueToUse = propertyValueToUse.AsString();
                        break;

                    case IFCDataPrimitiveType.Integer:
                        intValueToUse = propertyValueToUse.AsInteger();
                        break;

                    case IFCDataPrimitiveType.Boolean:
                        boolValueToUse = propertyValueToUse.AsBoolean();
                        break;

                    case IFCDataPrimitiveType.Logical:
                        logicalValueToUse = propertyValueToUse.AsLogical();
                        break;

                    case IFCDataPrimitiveType.Double:
                        if (propertyValueToUse.IFCUnit != null)
                        {
                            specTypeId  = propertyValueToUse.IFCUnit.Spec;
                            unitsTypeId = propertyValueToUse.IFCUnit.Unit;
                        }
                        else
                        {
                            specTypeId = IFCDataUtil.GetUnitTypeFromData(propertyValueToUse.Value, SpecTypeId.Number);
                        }

                        doubleValueToUse = Importer.TheProcessor.ScaleValues ?
                                           propertyValueToUse.AsScaledDouble() :
                                           propertyValueToUse.AsUnscaledDouble();
                        break;

                    default:
                        Importer.TheLog.LogError(Id, "Unknown value type for parameter: " + Name, false);
                        return;
                    }
                }
            }

            if (stringValueToUse != null && stringValueToUse.Length == 0)
            {
                return;
            }

            Parameter existingParameter     = null;
            bool      elementIsType         = (element is ElementType);
            string    typeString            = elementIsType ? " " + Resources.IFCTypeSchedule : string.Empty;
            string    originalParameterName = propertySetName + "." + Name + typeString;
            string    parameterName         = originalParameterName;

            if (parameterGroupMap.TryFindParameter(parameterName, out existingParameter))
            {
                if ((existingParameter != null) && !IsValidParameterType(existingParameter, dataType))
                {
                    existingParameter = null;
                }
            }

            if (existingParameter == null)
            {
                int parameterNameCount = 2;
                while (createdParameters.Contains(parameterName))
                {
                    parameterName = originalParameterName + " " + parameterNameCount;
                    parameterNameCount++;
                }
                if (parameterNameCount > 2)
                {
                    Importer.TheLog.LogWarning(Id, "Renamed parameter: " + originalParameterName + " to: " + parameterName, false);
                }

                bool created = false;
                switch (dataType)
                {
                case IFCDataPrimitiveType.String:
                case IFCDataPrimitiveType.Enumeration:
                case IFCDataPrimitiveType.Binary:
                    created = IFCPropertySet.AddParameterString(doc, element, category, objDef, parameterName, stringValueToUse, Id);
                    break;

                case IFCDataPrimitiveType.Integer:
                    created = IFCPropertySet.AddParameterInt(doc, element, category, objDef, parameterName, intValueToUse.Value, Id);
                    break;

                case IFCDataPrimitiveType.Boolean:
                    created = IFCPropertySet.AddParameterBoolean(doc, element, category, objDef, parameterName, boolValueToUse.Value, Id);
                    break;

                case IFCDataPrimitiveType.Logical:
                    if (logicalValueToUse != IFCLogical.Unknown)
                    {
                        created = IFCPropertySet.AddParameterBoolean(doc, element, category, objDef, parameterName, (logicalValueToUse == IFCLogical.True), Id);
                    }
                    break;

                case IFCDataPrimitiveType.Double:
                    created = IFCPropertySet.AddParameterDouble(doc, element, category, objDef, parameterName, specTypeId, unitsTypeId, doubleValueToUse.Value, Id);
                    break;

                case IFCDataPrimitiveType.Instance:
                    created = IFCPropertySet.AddParameterElementId(doc, element, category, objDef, parameterName, elementIdValueToUse, Id);
                    break;
                }

                if (created)
                {
                    createdParameters.Add(originalParameterName);
                }

                return;
            }

            bool couldSetValue = false;

            switch (existingParameter.StorageType)
            {
            case StorageType.String:
            {
                switch (dataType)
                {
                case IFCDataPrimitiveType.String:
                case IFCDataPrimitiveType.Enumeration:
                case IFCDataPrimitiveType.Binary:
                    couldSetValue = existingParameter.Set(stringValueToUse);
                    break;

                case IFCDataPrimitiveType.Integer:
                    couldSetValue = existingParameter.Set(intValueToUse.Value.ToString());
                    break;

                case IFCDataPrimitiveType.Boolean:
                    couldSetValue = existingParameter.Set(boolValueToUse.Value ? "True" : "False");
                    break;

                case IFCDataPrimitiveType.Logical:
                    couldSetValue = existingParameter.Set(logicalValueToUse.ToString());
                    break;

                case IFCDataPrimitiveType.Double:
                    couldSetValue = existingParameter.Set(doubleValueToUse.ToString());
                    break;

                default:
                    break;
                }
            }
            break;

            case StorageType.Integer:
                if (dataType == IFCDataPrimitiveType.Integer)
                {
                    couldSetValue = existingParameter.Set(intValueToUse.Value);
                }
                else if (dataType == IFCDataPrimitiveType.Boolean)
                {
                    couldSetValue = existingParameter.Set(boolValueToUse.Value ? 1 : 0);
                }
                else if (dataType == IFCDataPrimitiveType.Logical)
                {
                    couldSetValue = (logicalValueToUse == IFCLogical.Unknown) ? true : existingParameter.Set((logicalValueToUse == IFCLogical.True) ? 1 : 0);
                }
                break;

            case StorageType.Double:
                if (dataType == IFCDataPrimitiveType.Double)
                {
                    couldSetValue = existingParameter.Set(doubleValueToUse.Value);
                }
                else if (dataType == IFCDataPrimitiveType.Integer)
                {
                    couldSetValue = existingParameter.Set(intValueToUse.Value);
                }
                else if (dataType == IFCDataPrimitiveType.Boolean)
                {
                    couldSetValue = existingParameter.Set(boolValueToUse.Value ? 1 : 0);
                }
                else if ((dataType == IFCDataPrimitiveType.Logical) && (logicalValueToUse != IFCLogical.Unknown))
                {
                    couldSetValue = existingParameter.Set((logicalValueToUse == IFCLogical.True) ? 1 : 0);
                }
                break;
            }

            if (!couldSetValue)
            {
                Importer.TheLog.LogError(Id, "Couldn't create parameter: " + Name + " of storage type: " + existingParameter.StorageType.ToString(), false);
            }
        }
Beispiel #19
0
        /// <summary>
        /// Processes IfcProject attributes.
        /// </summary>
        /// <param name="ifcProjectHandle">The IfcProject handle.</param>
        protected override void Process(IFCAnyHandle ifcProjectHandle)
        {
            IFCAnyHandle unitsInContext = IFCImportHandleUtil.GetRequiredInstanceAttribute(ifcProjectHandle, "UnitsInContext", false);

            if (!IFCAnyHandleUtil.IsNullOrHasNoValue(unitsInContext))
            {
                IList <IFCAnyHandle> units = IFCAnyHandleUtil.GetAggregateInstanceAttribute <List <IFCAnyHandle> >(unitsInContext, "Units");

                if (units != null)
                {
                    m_UnitsInContext = new HashSet <IFCUnit>();

                    foreach (IFCAnyHandle unit in units)
                    {
                        IFCUnit ifcUnit = IFCImportFile.TheFile.IFCUnits.ProcessIFCProjectUnit(unit);
                        if (!IFCUnit.IsNullOrInvalid(ifcUnit))
                        {
                            m_UnitsInContext.Add(ifcUnit);
                        }
                    }
                }
                else
                {
                    Importer.TheLog.LogMissingRequiredAttributeError(unitsInContext, "Units", false);
                }
            }

            var application  = IFCImportFile.TheFile.Document.Application;
            var projectUnits = IFCImportFile.TheFile.IFCUnits.GetIFCProjectUnit(SpecTypeId.Length);

            IFCImportFile.TheFile.VertexTolerance     = application.VertexTolerance;
            IFCImportFile.TheFile.ShortCurveTolerance = application.ShortCurveTolerance;
            Importer.TheProcessor.PostProcessProject(projectUnits?.ScaleFactor, projectUnits?.Unit);

            // We need to process the units before we process the rest of the file, since we will scale values as we go along.
            base.Process(ifcProjectHandle);

            // process true north - take the first valid representation context that has a true north value.
            HashSet <IFCAnyHandle> repContexts = IFCAnyHandleUtil.GetAggregateInstanceAttribute <HashSet <IFCAnyHandle> >(ifcProjectHandle, "RepresentationContexts");

            bool   hasMapConv = false;
            XYZ    geoRef     = XYZ.Zero;
            string geoRefName = null;
            double trueNorth  = 0.0;

            if (repContexts != null)
            {
                foreach (IFCAnyHandle geomRepContextHandle in repContexts)
                {
                    if (!IFCAnyHandleUtil.IsNullOrHasNoValue(geomRepContextHandle) &&
                        IFCAnyHandleUtil.IsSubTypeOf(geomRepContextHandle, IFCEntityType.IfcGeometricRepresentationContext))
                    {
                        IFCRepresentationContext context = IFCRepresentationContext.ProcessIFCRepresentationContext(geomRepContextHandle);
                        if (TrueNorthDirection == null && context.TrueNorth != null)
                        {
                            // TODO: Verify that we don't have inconsistent true norths.  If we do, warn.
                            TrueNorthDirection = new UV(context.TrueNorth.X, context.TrueNorth.Y);
                        }

                        if (WorldCoordinateSystem == null && context.WorldCoordinateSystem != null && !context.WorldCoordinateSystem.IsIdentity)
                        {
                            WorldCoordinateSystem = context.WorldCoordinateSystem;
                        }

                        // Process Map Conversion if any
                        HashSet <IFCAnyHandle> coordOperation = IFCAnyHandleUtil.GetAggregateInstanceAttribute <HashSet <IFCAnyHandle> >(geomRepContextHandle, "HasCoordinateOperation");
                        if (coordOperation != null)
                        {
                            if (coordOperation.Count > 0)
                            {
                                if (IFCAnyHandleUtil.IsSubTypeOf(coordOperation.FirstOrDefault(), IFCEntityType.IfcMapConversion))
                                {
                                    hasMapConv = true;
                                    IFCAnyHandle mapConv  = coordOperation.FirstOrDefault();
                                    bool         found    = false;
                                    double       eastings = IFCImportHandleUtil.GetRequiredScaledLengthAttribute(mapConv, "Eastings", out found);
                                    if (!found)
                                    {
                                        eastings = 0.0;
                                    }
                                    double northings = IFCImportHandleUtil.GetRequiredScaledLengthAttribute(mapConv, "Northings", out found);
                                    if (!found)
                                    {
                                        northings = 0.0;
                                    }
                                    double orthogonalHeight = IFCImportHandleUtil.GetRequiredScaledLengthAttribute(mapConv, "OrthogonalHeight", out found);
                                    if (!found)
                                    {
                                        orthogonalHeight = 0.0;
                                    }
                                    double xAxisAbs = IFCImportHandleUtil.GetOptionalRealAttribute(mapConv, "XAxisAbscissa", 1.0);
                                    double xAxisOrd = IFCImportHandleUtil.GetOptionalRealAttribute(mapConv, "XAxisOrdinate", 0.0);
                                    trueNorth = Math.Atan2(xAxisOrd, xAxisAbs);
                                    //angleToNorth = -((xAxisAngle > -Math.PI / 2.0) ? xAxisAngle - Math.PI / 2.0 : xAxisAngle + Math.PI * 1.5);
                                    double scale = IFCImportHandleUtil.GetOptionalRealAttribute(mapConv, "Scale", 1.0);
                                    geoRef = new XYZ(scale * eastings, scale * northings, scale * orthogonalHeight);

                                    // Process the IfcProjectedCRS
                                    IFCAnyHandle projCRS = IFCAnyHandleUtil.GetInstanceAttribute(mapConv, "TargetCRS");
                                    if (projCRS != null && IFCAnyHandleUtil.IsSubTypeOf(projCRS, IFCEntityType.IfcProjectedCRS))
                                    {
                                        geoRefName = IFCImportHandleUtil.GetRequiredStringAttribute(projCRS, "Name", false);
                                        string       desc          = IFCImportHandleUtil.GetOptionalStringAttribute(projCRS, "Description", null);
                                        string       geodeticDatum = IFCImportHandleUtil.GetOptionalStringAttribute(projCRS, "GeodeticDatum", null);
                                        string       verticalDatum = IFCImportHandleUtil.GetOptionalStringAttribute(projCRS, "VerticalDatum", null);
                                        string       mapProj       = IFCImportHandleUtil.GetOptionalStringAttribute(projCRS, "MapProjection", null);
                                        string       mapZone       = IFCImportHandleUtil.GetOptionalStringAttribute(projCRS, "MapZone", null);
                                        IFCAnyHandle mapUnit       = IFCImportHandleUtil.GetOptionalInstanceAttribute(projCRS, "MapUnit");

                                        Document    doc         = IFCImportFile.TheFile.Document;
                                        ProjectInfo projectInfo = doc.ProjectInformation;

                                        // We add this here because we want to make sure that external processors (e.g., Navisworks)
                                        // get a chance to add a container for the parameters that get added below.  In general,
                                        // we should probably augment Processor.AddParameter to ensure that CreateOrUpdateElement
                                        // is called before anything is attempted to be added.  This is a special case, though,
                                        // as in Revit we don't actually create an element for the IfcProject.
                                        Importer.TheProcessor.CreateOrUpdateElement(Id, GlobalId, EntityType.ToString(), CategoryId.IntegerValue, null);

                                        Category category = IFCPropertySet.GetCategoryForParameterIfValid(projectInfo, Id);
                                        IFCPropertySet.AddParameterString(doc, projectInfo, category, this, "IfcProjectedCRS.Name", geoRefName, Id);
                                        if (!string.IsNullOrEmpty(desc))
                                        {
                                            IFCPropertySet.AddParameterString(doc, projectInfo, category, this, "IfcProjectedCRS.Description", desc, Id);
                                        }
                                        if (!string.IsNullOrEmpty(geodeticDatum))
                                        {
                                            IFCPropertySet.AddParameterString(doc, projectInfo, category, this, "IfcProjectedCRS.GeodeticDatum", geodeticDatum, Id);
                                        }
                                        if (!string.IsNullOrEmpty(verticalDatum))
                                        {
                                            IFCPropertySet.AddParameterString(doc, projectInfo, category, this, "IfcProjectedCRS.VerticalDatum", verticalDatum, Id);
                                        }
                                        if (!string.IsNullOrEmpty(mapProj))
                                        {
                                            IFCPropertySet.AddParameterString(doc, projectInfo, category, this, "IfcProjectedCRS.MapProjection", mapProj, Id);
                                        }
                                        if (!string.IsNullOrEmpty(mapZone))
                                        {
                                            IFCPropertySet.AddParameterString(doc, projectInfo, category, this, "IfcProjectedCRS.MapZone", mapZone, Id);
                                        }
                                        if (!IFCAnyHandleUtil.IsNullOrHasNoValue(mapUnit))
                                        {
                                            IFCUnit mapUnitIfc = IFCUnit.ProcessIFCUnit(mapUnit);
                                            string  unitStr    = UnitUtils.GetTypeCatalogStringForUnit(mapUnitIfc.Unit);
                                            IFCPropertySet.AddParameterString(doc, projectInfo, category, this, "IfcProjectedCRS.MapUnit", unitStr, Id);
                                            double convFactor = UnitUtils.Convert(1.0, mapUnitIfc.Unit, IFCImportFile.TheFile.IFCUnits.GetIFCProjectUnit(SpecTypeId.Length).Unit);
                                            eastings         = convFactor * eastings;
                                            northings        = convFactor * northings;
                                            orthogonalHeight = convFactor * orthogonalHeight;
                                            geoRef           = new XYZ(eastings, northings, orthogonalHeight);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                ProjectLocation projectLocation = IFCImportFile.TheFile.Document.ActiveProjectLocation;
                ProjectPosition projectPosition;
                if (projectLocation != null)
                {
                    if (hasMapConv)
                    {
                        projectPosition = new ProjectPosition(geoRef.X, geoRef.Y, geoRef.Z, trueNorth);
                        projectLocation.SetProjectPosition(XYZ.Zero, projectPosition);

                        if (!string.IsNullOrEmpty(geoRefName))
                        {
                            IFCImportFile.TheFile.Document.SiteLocation.SetGeoCoordinateSystem(geoRefName);
                        }
                    }
                    else
                    {
                        // Set initial project location based on the information above.
                        // This may be further modified by the site.
                        trueNorth = 0.0;
                        if (TrueNorthDirection != null)
                        {
                            trueNorth = -Math.Atan2(-TrueNorthDirection.U, TrueNorthDirection.V);
                        }

                        // TODO: Extend this to work properly if the world coordinate system
                        // isn't a simple translation.
                        XYZ origin = XYZ.Zero;
                        if (WorldCoordinateSystem != null)
                        {
                            geoRef = WorldCoordinateSystem.Origin;
                            double angleRot = Math.Atan2(WorldCoordinateSystem.BasisX.Y, WorldCoordinateSystem.BasisX.X);

                            // If it is translation only, or if the WCS rotation is equal to trueNorth, we assume they are the same
                            if (WorldCoordinateSystem.IsTranslation ||
                                MathUtil.IsAlmostEqual(angleRot, trueNorth))
                            {
                                WorldCoordinateSystem = null;
                            }
                            else
                            {
                                // If the trueNorth is not set (=0), set the trueNorth by the rotation of the WCS, otherwise add the angle
                                if (MathUtil.IsAlmostZero(trueNorth))
                                {
                                    trueNorth = angleRot;
                                }
                                else
                                {
                                    trueNorth += angleRot;
                                }

                                WorldCoordinateSystem = null;
                            }
                        }

                        projectPosition = new ProjectPosition(geoRef.X, geoRef.Y, geoRef.Z, trueNorth);
                        projectLocation.SetProjectPosition(XYZ.Zero, projectPosition);
                    }
                }
            }
        }
        protected virtual void CreateParametersInternal(Document doc, Element element)
        {
            if (element != null)
            {
                Category category = IFCPropertySet.GetCategoryForParameterIfValid(element, Id);

                // Set the element name.
                SetName(doc, element, category);

                // Set the element description.
                SetDescription(doc, element, category);

                // The list of materials.
                SetMaterialParameter(doc, element, category);

                // Set the "IfcSystem" parameter.
                SetSystemParameter(doc, element, category);

                // Set the element GUID.
                bool             elementIsType = (element is ElementType);
                BuiltInParameter ifcGUIDId     = GetGUIDParameter(element, elementIsType);
                Parameter        guidParam     = element.get_Parameter(ifcGUIDId);
                if (guidParam != null)
                {
                    if (!guidParam.IsReadOnly)
                    {
                        guidParam.Set(GlobalId);
                    }
                }
                else
                {
                    ExporterIFCUtils.AddValueString(element, new ElementId(ifcGUIDId), GlobalId);
                }

                // Set the "IfcExportAs" parameter.
                string ifcExportAs = IFCCategoryUtil.GetCustomCategoryName(this);
                if (!string.IsNullOrWhiteSpace(ifcExportAs))
                {
                    IFCPropertySet.AddParameterString(doc, element, category, this, IFCSharedParameters.IfcExportAs, ifcExportAs, Id);
                }

                // Set the IFCElementAssembly Parameter
                if (Decomposes != null)
                {
                    string containerParamName     = (Decomposes is IFCElementAssembly) ? "IfcElementAssembly" : "IfcDecomposes";
                    string containerParamGUIDName = (Decomposes is IFCElementAssembly) ? "IfcElementAssemblyGUID" : "IfcDecomposesGUID";
                    IFCPropertySet.AddParameterString(doc, element, category, containerParamName, Decomposes.Name, Id);
                    IFCPropertySet.AddParameterString(doc, element, category, containerParamGUIDName, Decomposes.GlobalId, Id);
                }

                // Set additional parameters (if any), e.g. for Classification assignments
                if (AdditionalIntParameters.Count > 0)
                {
                    foreach (KeyValuePair <string, object> parItem in AdditionalIntParameters)
                    {
                        if (parItem.Value is string)
                        {
                            IFCPropertySet.AddParameterString(doc, element, category, parItem.Key, (string)parItem.Value, Id);
                        }
                        else if (parItem.Value is double)
                        {
                            IFCPropertySet.AddParameterDouble(doc, element, category, parItem.Key, SpecTypeId.Custom, (double)parItem.Value, Id);
                        }
                        else if (parItem.Value is int)
                        {
                            IFCPropertySet.AddParameterInt(doc, element, category, parItem.Key, (int)parItem.Value, Id);
                        }
                        else if (parItem.Value is bool)
                        {
                            IFCPropertySet.AddParameterBoolean(doc, element, category, parItem.Key, (bool)parItem.Value, Id);
                        }
                    }
                }
            }
        }
Beispiel #21
0
        protected virtual void CreateParametersInternal(Document doc, Element element)
        {
            if (element != null)
            {
                // Set the element name.
                SetName(doc, element);

                // Set the element description.
                SetDescription(doc, element);

                // The list of materials.
                SetMaterialParameter(doc, element);

                // Set the "IfcSystem" parameter.
                SetSystemParameter(doc, element);

                // Set the element GUID.
                bool             elementIsType = (element is ElementType);
                BuiltInParameter ifcGUIDId     = GetGUIDParameter(element, elementIsType);
                Parameter        guidParam     = element.get_Parameter(ifcGUIDId);
                if (guidParam != null)
                {
                    if (!guidParam.IsReadOnly)
                    {
                        guidParam.Set(GlobalId);
                    }
                }
                else
                {
                    ExporterIFCUtils.AddValueString(element, new ElementId(ifcGUIDId), GlobalId);
                }

                // Set the "IfcExportAs" parameter.
                string ifcExportAs = IFCCategoryUtil.GetCustomCategoryName(this);
                if (!string.IsNullOrWhiteSpace(ifcExportAs))
                {
                    IFCPropertySet.AddParameterString(doc, element, "IfcExportAs", ifcExportAs, Id);
                }

                // Add property set-based parameters.
                // We are going to create this "fake" parameter so that we can filter elements in schedules based on their property sets.
                string propertySetListName = elementIsType ? "Type IfcPropertySetList" : "IfcPropertySetList";
                IFCPropertySet.AddParameterString(doc, element, propertySetListName, "", Id);

                // Set the IFCElementAssembly Parameter
                if (Decomposes != null && Decomposes is IFCElementAssembly)
                {
                    IFCPropertySet.AddParameterString(doc, element, "IfcElementAssembly", Decomposes.Name, Id);
                }

                // Set additional parameters (if any), e.g. for Classification assignments
                if (AdditionalIntParameters.Count > 0)
                {
                    foreach (KeyValuePair <string, object> parItem in AdditionalIntParameters)
                    {
                        if (parItem.Value is string)
                        {
                            IFCPropertySet.AddParameterString(doc, element, parItem.Key, (string)parItem.Value, Id);
                        }
                        else if (parItem.Value is double)
                        {
                            IFCPropertySet.AddParameterDouble(doc, element, parItem.Key, UnitType.UT_Custom, (double)parItem.Value, Id);
                        }
                        else if (parItem.Value is int)
                        {
                            IFCPropertySet.AddParameterInt(doc, element, parItem.Key, (int)parItem.Value, Id);
                        }
                        else if (parItem.Value is bool)
                        {
                            IFCPropertySet.AddParameterBoolean(doc, element, parItem.Key, (bool)parItem.Value, Id);
                        }
                    }
                }
            }
        }
        protected virtual void CreateParametersInternal(Document doc, Element element)
        {
            if (element != null)
            {
                Category category = IFCPropertySet.GetCategoryForParameterIfValid(element, Id);

                Importer.TheProcessor.CreateOrUpdateElement(Id, GlobalId, EntityType.ToString(), CategoryId.IntegerValue, null);

                // Set the element name.
                SetName(doc, element, category);

                // Set the element description.
                SetDescription(doc, element, category);

                // The list of materials.
                SetMaterialParameter(doc, element, category);

                // Set the "IfcSystem" parameter.
                SetSystemParameter(doc, element, category);

                bool elementIsType = (element is ElementType);
                if (!string.IsNullOrWhiteSpace(GlobalId))
                {
                    BuiltInParameter ifcGUIDId = GetGUIDParameter(element, elementIsType);
                    Importer.TheProcessor.SetStringParameter(element, Id, ifcGUIDId, GlobalId, true);
                }

                // Set the built-in parameters.
                (string entityName, string predefinedType) = IFCCategoryUtil.GetEntityNameAndPredefinedType(this);
                if (!string.IsNullOrWhiteSpace(entityName))
                {
                    BuiltInParameter ifcExportElementAsParam = elementIsType ? BuiltInParameter.IFC_EXPORT_ELEMENT_TYPE_AS : BuiltInParameter.IFC_EXPORT_ELEMENT_AS;
                    Importer.TheProcessor.SetStringParameter(element, Id, ifcExportElementAsParam, entityName, true);
                }

                if (!string.IsNullOrWhiteSpace(predefinedType))
                {
                    BuiltInParameter ifcPredefinedTypeParam = elementIsType ? BuiltInParameter.IFC_EXPORT_PREDEFINEDTYPE_TYPE : BuiltInParameter.IFC_EXPORT_PREDEFINEDTYPE;
                    Importer.TheProcessor.SetStringParameter(element, Id, ifcPredefinedTypeParam, predefinedType, true);
                }
                // Set the IFCElementAssembly Parameter
                if (Decomposes != null)
                {
                    string containerParamName     = (Decomposes is IFCElementAssembly) ? "IfcElementAssembly" : "IfcDecomposes";
                    string containerParamGUIDName = (Decomposes is IFCElementAssembly) ? "IfcElementAssemblyGUID" : "IfcDecomposesGUID";
                    IFCPropertySet.AddParameterString(doc, element, category, this, containerParamName, Decomposes.Name, Id);
                    IFCPropertySet.AddParameterString(doc, element, category, this, containerParamGUIDName, Decomposes.GlobalId, Id);
                }

                // Set additional parameters (if any), e.g. for Classification assignments
                if (AdditionalIntParameters.Count > 0)
                {
                    foreach (KeyValuePair <string, object> parItem in AdditionalIntParameters)
                    {
                        if (parItem.Value is string)
                        {
                            IFCPropertySet.AddParameterString(doc, element, category, this, parItem.Key, (string)parItem.Value, Id);
                        }
                        else if (parItem.Value is double)
                        {
                            IFCPropertySet.AddParameterDouble(doc, element, category, this, parItem.Key, SpecTypeId.Custom, UnitTypeId.General, (double)parItem.Value, Id);
                        }
                        else if (parItem.Value is int)
                        {
                            IFCPropertySet.AddParameterInt(doc, element, category, this, parItem.Key, (int)parItem.Value, Id);
                        }
                        else if (parItem.Value is bool)
                        {
                            IFCPropertySet.AddParameterBoolean(doc, element, category, this, parItem.Key, (bool)parItem.Value, Id);
                        }
                    }
                }
            }
        }