Пример #1
0
        /// <summary>
        /// Processes an IfcWindowPanelProperties entity.
        /// </summary>
        /// <param name="ifcWindowPanelProperties">The IfcWindowPanelProperties handle.</param>
        protected override void Process(IFCAnyHandle ifcWindowPanelProperties)
        {
            base.Process(ifcWindowPanelProperties);

            string currPropertyValueString = IFCImportHandleUtil.GetOptionalStringAttribute(ifcWindowPanelProperties, "OperationType", null);

            if (!string.IsNullOrEmpty(currPropertyValueString))
            {
                StringProperties[GeneratePropertyName("OperationType")] = currPropertyValueString;
            }

            currPropertyValueString = IFCImportHandleUtil.GetOptionalStringAttribute(ifcWindowPanelProperties, "PanelPosition", null);
            if (!string.IsNullOrEmpty(currPropertyValueString))
            {
                StringProperties[GeneratePropertyName("PanelPosition")] = currPropertyValueString;
            }

            double currPropertyValue = IFCImportHandleUtil.GetOptionalScaledLengthAttribute(ifcWindowPanelProperties, "FrameDepth", -1e+30);

            if (!MathUtil.IsAlmostEqual(currPropertyValue, -1e+30))
            {
                DoubleProperties[new Tuple <string, UnitType, AllowedValues>(GeneratePropertyName("FrameDepth"),
                                                                             UnitType.UT_Length, AllowedValues.Positive)] = currPropertyValue;
            }

            currPropertyValue = IFCImportHandleUtil.GetOptionalScaledLengthAttribute(ifcWindowPanelProperties, "FrameThickness", -1e+30);
            if (!MathUtil.IsAlmostEqual(currPropertyValue, -1e+30))
            {
                DoubleProperties[new Tuple <string, UnitType, AllowedValues>(GeneratePropertyName("FrameThickness"),
                                                                             UnitType.UT_Length, AllowedValues.Positive)] = currPropertyValue;
            }
        }
        /// <summary>
        /// Processes IfcRepresentationContext attributes.
        /// </summary>
        /// <param name="ifcRepresentationContext">The IfcRepresentationContext handle.</param>
        override protected void Process(IFCAnyHandle ifcRepresentationContext)
        {
            base.Process(ifcRepresentationContext);

            Identifier = IFCImportHandleUtil.GetOptionalStringAttribute(ifcRepresentationContext, "ContextIdentifier", null);

            Type = IFCImportHandleUtil.GetOptionalStringAttribute(ifcRepresentationContext, "ContextType", null);

            if (IFCAnyHandleUtil.IsSubTypeOf(ifcRepresentationContext, IFCEntityType.IfcGeometricRepresentationContext))
            {
                bool found = false;
                CoordinateSpaceDimension = IFCImportHandleUtil.GetRequiredIntegerAttribute(ifcRepresentationContext, "CoordinateSpaceDimension", out found);
                if (!found)
                {
                    CoordinateSpaceDimension = 3;   // Don't throw, just set to default 3D.
                }
                Precision = IFCImportHandleUtil.GetOptionalScaledLengthAttribute(ifcRepresentationContext, "Precision", IFCImportFile.TheFile.Document.Application.VertexTolerance);

                IFCAnyHandle worldCoordinateSystem = IFCImportHandleUtil.GetRequiredInstanceAttribute(ifcRepresentationContext, "WorldCoordinateSystem", false);
                if (!IFCAnyHandleUtil.IsNullOrHasNoValue(worldCoordinateSystem))
                {
                    WorldCoordinateSystem = IFCLocation.ProcessIFCAxis2Placement(worldCoordinateSystem);
                }
                else
                {
                    WorldCoordinateSystem = Transform.Identity;
                }

                // For IfcGeometricRepresentationSubContext, it seems as if
                try
                {
                    IFCAnyHandle trueNorth = IFCImportHandleUtil.GetOptionalInstanceAttribute(ifcRepresentationContext, "TrueNorth");
                    if (!IFCAnyHandleUtil.IsNullOrHasNoValue(trueNorth))
                    {
                        TrueNorth = IFCPoint.ProcessNormalizedIFCDirection(trueNorth);
                    }
                    else
                    {
                        TrueNorth = XYZ.BasisZ;
                    }
                }
                catch
                {
                    TrueNorth = XYZ.BasisZ;
                }

                if (IFCAnyHandleUtil.IsSubTypeOf(ifcRepresentationContext, IFCEntityType.IfcGeometricRepresentationSubContext))
                {
                    IFCAnyHandle parentContext = IFCImportHandleUtil.GetRequiredInstanceAttribute(ifcRepresentationContext, "ParentContext", true);
                    ParentContext = IFCRepresentationContext.ProcessIFCRepresentationContext(parentContext);

                    TargetScale = IFCImportHandleUtil.GetOptionalPositiveRatioAttribute(ifcRepresentationContext, "TargetScale", 1.0);

                    TargetView = IFCEnums.GetSafeEnumerationAttribute <IFCGeometricProjection>(ifcRepresentationContext, "TargetView",
                                                                                               IFCGeometricProjection.NotDefined);

                    UserDefinedTargetView = IFCImportHandleUtil.GetOptionalStringAttribute(ifcRepresentationContext, "UserDefinedTargetView", null);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Processes an IFC physical quantity.
        /// </summary>
        /// <param name="ifcPhysicalQuantity">The IfcPhysicalQuantity object.</param>
        /// <returns>The IFCPhysicalQuantity object.</returns>
        override protected void Process(IFCAnyHandle ifcPhysicalQuantity)
        {
            base.Process(ifcPhysicalQuantity);

            Name = IFCImportHandleUtil.GetRequiredStringAttribute(ifcPhysicalQuantity, "Name", true);

            Description = IFCImportHandleUtil.GetOptionalStringAttribute(ifcPhysicalQuantity, "Description", null);
        }
        /// <summary>
        /// Processes IfcProductRepresentation attributes.
        /// </summary>
        /// <param name="ifcProductRepresentation">The IfcProductRepresentation handle.</param>
        protected override void Process(IFCAnyHandle ifcProductRepresentation)
        {
            base.Process(ifcProductRepresentation);

            Name = IFCImportHandleUtil.GetOptionalStringAttribute(ifcProductRepresentation, "Name", null);

            Description = IFCImportHandleUtil.GetOptionalStringAttribute(ifcProductRepresentation, "Description", null);

            List <IFCAnyHandle> representations =
                IFCAnyHandleUtil.GetAggregateInstanceAttribute <List <IFCAnyHandle> >(ifcProductRepresentation, "Representations");

            if (representations != null)
            {
                foreach (IFCAnyHandle representationHnd in representations)
                {
                    try
                    {
                        IFCRepresentation representation = IFCRepresentation.ProcessIFCRepresentation(representationHnd);
                        if (representation != null)
                        {
                            if (representation.RepresentationItems.Count > 0 || representation.BoundingBox != null)
                            {
                                Representations.Add(representation);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        string msg = ex.Message;
                        // Ignore some specific errors.
                        if (msg != null)
                        {
                            if (!msg.Contains("not imported"))
                            {
                                Importer.TheLog.LogError(Id, msg, false);
                            }
                        }
                    }
                }
            }

            if (IFCImportFile.TheFile.SchemaVersion >= IFCSchemaVersion.IFC2x3)
            {
                if (IFCAnyHandleUtil.IsSubTypeOf(ifcProductRepresentation, IFCEntityType.IfcMaterialDefinitionRepresentation))
                {
                    IFCAnyHandle representedMaterial = IFCImportHandleUtil.GetRequiredInstanceAttribute(ifcProductRepresentation, "RepresentedMaterial", false);
                    if (!IFCAnyHandleUtil.IsNullOrHasNoValue(representedMaterial))
                    {
                        RepresentedMaterial = IFCMaterial.ProcessIFCMaterial(representedMaterial);
                    }
                }
            }
        }
Пример #5
0
        override protected void Process(IFCAnyHandle item)
        {
            base.Process(item);

            Name = IFCImportHandleUtil.GetOptionalStringAttribute(item, "Name", null);

            Description = IFCImportHandleUtil.GetOptionalStringAttribute(item, "Description", null);

            Identifier = IFCImportHandleUtil.GetOptionalStringAttribute(item, "Identifier", null);

            // We do NOT process AssignedItems here.  That is pre-processed to avoid INVERSE attribute calls.
        }
Пример #6
0
        override protected void Process(IFCAnyHandle styledItem)
        {
            base.Process(styledItem);

            IFCAnyHandle item = IFCImportHandleUtil.GetOptionalInstanceAttribute(styledItem, "Item");

            if (!IFCAnyHandleUtil.IsNullOrHasNoValue(item))
            {
                Item = IFCRepresentationItem.ProcessIFCRepresentationItem(item);
            }

            Name = IFCImportHandleUtil.GetOptionalStringAttribute(styledItem, "Name", null);

            List <IFCAnyHandle> styles = IFCAnyHandleUtil.GetAggregateInstanceAttribute <List <IFCAnyHandle> >(styledItem, "Styles");

            if (styles == null || styles.Count == 0)
            {
                Importer.TheLog.LogMissingRequiredAttributeError(styledItem, "Styles", true);
            }

            foreach (IFCAnyHandle style in styles)
            {
                if (IFCAnyHandleUtil.IsNullOrHasNoValue(style))
                {
                    continue;
                }

                if (IFCImportFile.TheFile.SchemaVersionAtLeast(IFCSchemaVersion.IFC4Obsolete) && IFCAnyHandleUtil.IsValidSubTypeOf(style, IFCEntityType.IfcPresentationStyle))
                {
                    Styles.Add(IFCPresentationStyle.ProcessIFCPresentationStyle(style));
                }
                else
                {
                    if (Styles.Count != 0)
                    {
                        Importer.TheLog.LogWarning(styledItem.StepId, "Multiple presentation styles found for IfcStyledItem - using first.", false);
                        continue;
                    }

                    IFCPresentationStyleAssignment presentationStyleAssignment =
                        IFCPresentationStyleAssignment.ProcessIFCPresentationStyleAssignment(style);
                    if (presentationStyleAssignment != null && presentationStyleAssignment.Styles != null)
                    {
                        Styles.AddRange(presentationStyleAssignment.Styles);
                    }
                }
            }
        }
Пример #7
0
        override protected void Process(IFCAnyHandle item)
        {
            base.Process(item);

            Name = IFCImportHandleUtil.GetOptionalStringAttribute(item, "Name", null);

            Description = IFCImportHandleUtil.GetOptionalStringAttribute(item, "Description", null);

            Identifier = IFCImportHandleUtil.GetOptionalStringAttribute(item, "Identifier", null);

            IList <IFCAnyHandle> assignedItems = IFCAnyHandleUtil.GetAggregateInstanceAttribute <List <IFCAnyHandle> >(item, "AssignedItems");

            foreach (IFCAnyHandle assignedItem in assignedItems)
            {
                // We do NOT process items here.  We only use already created representations and representation items.
                IFCEntity entity = null;
                if (!IFCImportFile.TheFile.EntityMap.TryGetValue(assignedItem.StepId, out entity))
                {
                    continue;
                }

                if (IFCAnyHandleUtil.IsSubTypeOf(assignedItem, IFCEntityType.IfcRepresentation))
                {
                    (entity as IFCRepresentation).PostProcessLayerAssignment(this);
                }
                else if (IFCAnyHandleUtil.IsSubTypeOf(assignedItem, IFCEntityType.IfcRepresentationItem))
                {
                    (entity as IFCRepresentationItem).PostProcessLayerAssignment(this);
                }

                if (entity != null)
                {
                    AssignedItems.Add(entity);
                }
                else
                {
                    Importer.TheLog.LogUnhandledSubTypeError(assignedItem, "IfcLayeredItem", false);
                }
            }
        }
Пример #8
0
        protected override void Process(IFCAnyHandle ifcMaterialProfileSet)
        {
            base.Process(ifcMaterialProfileSet);

            IList <IFCAnyHandle> ifcMaterialProfiles =
                IFCAnyHandleUtil.GetAggregateInstanceAttribute <List <IFCAnyHandle> >(ifcMaterialProfileSet, "MaterialProfiles");

            if (ifcMaterialProfiles == null)
            {
                Importer.TheLog.LogError(ifcMaterialProfileSet.Id, "Expected at least 1 MaterialProfile, found none.", false);
                return;
            }

            foreach (IFCAnyHandle ifcMaterialProfile in ifcMaterialProfiles)
            {
                IFCMaterialProfile materialProfile = null;
                if (IFCAnyHandleUtil.IsTypeOf(ifcMaterialProfile, IFCEntityType.IfcMaterialProfileWithOffsets))
                {
                    materialProfile = IFCMaterialProfileWithOffsets.ProcessIFCMaterialProfileWithOffsets(ifcMaterialProfile);
                }
                else
                {
                    materialProfile = IFCMaterialProfile.ProcessIFCMaterialProfile(ifcMaterialProfile);
                }

                if (materialProfile != null)
                {
                    MaterialProfileSet.Add(materialProfile);
                }
            }

            Name        = IFCImportHandleUtil.GetOptionalStringAttribute(ifcMaterialProfileSet, "Name", null);
            Description = IFCImportHandleUtil.GetOptionalStringAttribute(ifcMaterialProfileSet, "Description", null);
            IFCAnyHandle compositeProfileHnd = IFCImportHandleUtil.GetOptionalInstanceAttribute(ifcMaterialProfileSet, "CompositeProfile");

            if (!IFCAnyHandleUtil.IsNullOrHasNoValue(compositeProfileHnd))
            {
                CompositeProfile = IFCCompositeProfile.ProcessIFCCompositeProfile(compositeProfileHnd);
            }
        }
        protected override void Process(IFCAnyHandle ifcMaterialConstituent)
        {
            base.Process(ifcMaterialConstituent);

            IFCAnyHandle ifcMaterial = IFCImportHandleUtil.GetRequiredInstanceAttribute(ifcMaterialConstituent, "Material", true);

            if (!IFCAnyHandleUtil.IsNullOrHasNoValue(ifcMaterial))
            {
                Material = IFCMaterial.ProcessIFCMaterial(ifcMaterial);
            }

            Name        = IFCImportHandleUtil.GetOptionalStringAttribute(ifcMaterialConstituent, "Name", null);
            Description = IFCImportHandleUtil.GetOptionalStringAttribute(ifcMaterialConstituent, "Description", null);
            double fraction = IFCImportHandleUtil.GetOptionalRealAttribute(ifcMaterialConstituent, "Fraction", -1);

            if (fraction >= 0)
            {
                Fraction = fraction;
            }
            Category = IFCImportHandleUtil.GetOptionalStringAttribute(ifcMaterialConstituent, "Category", null);
            return;
        }
Пример #10
0
        /// <summary>
        /// Processes IfcSpatialStructureElement attributes.
        /// </summary>
        /// <param name="ifcSpatialStructureElement">The IfcSpatialStructureElement handle.</param>
        protected override void Process(IFCAnyHandle ifcSpatialStructureElement)
        {
            base.Process(ifcSpatialStructureElement);

            LongName = IFCImportHandleUtil.GetOptionalStringAttribute(ifcSpatialStructureElement, "LongName", null);

            HashSet <IFCAnyHandle> elemSet =
                IFCAnyHandleUtil.GetAggregateInstanceAttribute <HashSet <IFCAnyHandle> >(ifcSpatialStructureElement, "ContainsElements");

            if (elemSet != null)
            {
                if (m_IFCProducts == null)
                {
                    m_IFCProducts = new HashSet <IFCProduct>();
                }

                foreach (IFCAnyHandle elem in elemSet)
                {
                    ProcessIFCRelContainedInSpatialStructure(elem);
                }
            }

            HashSet <IFCAnyHandle> systemSet =
                IFCAnyHandleUtil.GetAggregateInstanceAttribute <HashSet <IFCAnyHandle> >(ifcSpatialStructureElement, "ServicedBySystems");

            if (systemSet != null)
            {
                if (m_IFCSystems == null)
                {
                    m_IFCSystems = new HashSet <IFCGroup>();
                }

                foreach (IFCAnyHandle system in systemSet)
                {
                    ProcessIFCRelServicesBuildings(system);
                }
            }
        }
Пример #11
0
        protected override void Process(IFCAnyHandle ifcMaterialLayerSet)
        {
            base.Process(ifcMaterialLayerSet);

            IList <IFCAnyHandle> ifcMaterialLayers =
                IFCAnyHandleUtil.GetAggregateInstanceAttribute <List <IFCAnyHandle> >(ifcMaterialLayerSet, "MaterialLayers");

            if (ifcMaterialLayers == null)
            {
                Importer.TheLog.LogError(ifcMaterialLayerSet.Id, "Expected at least 1 IfcMaterialLayer, found none.", false);
                return;
            }

            foreach (IFCAnyHandle ifcMaterialLayer in ifcMaterialLayers)
            {
                IFCMaterialLayer materialLayer = IFCMaterialLayer.ProcessIFCMaterialLayer(ifcMaterialLayer);
                if (materialLayer != null)
                {
                    MaterialLayers.Add(materialLayer);
                }
            }

            LayerSetName = IFCImportHandleUtil.GetOptionalStringAttribute(ifcMaterialLayerSet, "LayerSetName", null);
        }
Пример #12
0
        /// <summary>
        /// Processes an IfcDerivedUnit.
        /// </summary>
        /// <param name="unitHnd">The unit handle.</param>
        void ProcessIFCDerivedUnit(IFCAnyHandle unitHnd)
        {
            List <IFCAnyHandle> elements =
                IFCAnyHandleUtil.GetAggregateInstanceAttribute <List <IFCAnyHandle> >(unitHnd, "Elements");

            IList <KeyValuePair <IFCUnit, int> > derivedElementUnitHnds = new List <KeyValuePair <IFCUnit, int> >();

            foreach (IFCAnyHandle subElement in elements)
            {
                IFCAnyHandle derivedElementUnitHnd = IFCImportHandleUtil.GetRequiredInstanceAttribute(subElement, "Unit", false);
                IFCUnit      subUnit = IFCAnyHandleUtil.IsNullOrHasNoValue(derivedElementUnitHnd) ? null : IFCUnit.ProcessIFCUnit(derivedElementUnitHnd);
                if (subUnit != null)
                {
                    bool found;
                    int  exponent = IFCImportHandleUtil.GetRequiredIntegerAttribute(subElement, "Exponent", out found);
                    if (found)
                    {
                        derivedElementUnitHnds.Add(new KeyValuePair <IFCUnit, int>(subUnit, exponent));
                    }
                }
            }

            // the DerivedUnitExpectedTypes object is a description of one possible set of base units for a particular derived unit.
            // The IList allows for possible different interpretations.  For example, Volumetric Flow Rate could be defined by m^3/s (length ^ 3 / time) or L/s (volume / time).
            IList <DerivedUnitExpectedTypes> expectedTypesList = new List <DerivedUnitExpectedTypes>();

            string unitType = IFCAnyHandleUtil.GetEnumerationAttribute(unitHnd, "UnitType");

            if (string.Compare(unitType, "LINEARVELOCITYUNIT", true) == 0)
            {
                Spec       = SpecTypeId.HvacVelocity;
                UnitSystem = UnitSystem.Metric;

                // Support only m / s.
                DerivedUnitExpectedTypes expectedTypes = new DerivedUnitExpectedTypes(UnitTypeId.MetersPerSecond, SymbolTypeId.MPerS);
                expectedTypes.AddExpectedType(1, SpecTypeId.Length);
                expectedTypes.AddCustomExpectedType(-1, "TIMEUNIT");
                expectedTypesList.Add(expectedTypes);
            }
            else if (string.Compare(unitType, "THERMALTRANSMITTANCEUNIT", true) == 0)
            {
                Spec       = SpecTypeId.HeatTransferCoefficient;
                UnitSystem = UnitSystem.Metric;

                // Support W / (K * m^2) or kg / (K * s^3)
                DerivedUnitExpectedTypes expectedTypesWinvKinvM2 = new DerivedUnitExpectedTypes(UnitTypeId.WattsPerSquareMeterKelvin, SymbolTypeId.WPerMSup2K);
                expectedTypesWinvKinvM2.AddExpectedType(1, SpecTypeId.HvacPower); // UT_Electrical_Wattage is similar, but UT_HVAC_Power is the one we map to.
                expectedTypesWinvKinvM2.AddExpectedType(-1, SpecTypeId.HvacTemperature);
                expectedTypesWinvKinvM2.AddExpectedType(-2, SpecTypeId.Length);
                expectedTypesList.Add(expectedTypesWinvKinvM2);

                DerivedUnitExpectedTypes expectedTypesWinvKinvArea = new DerivedUnitExpectedTypes(UnitTypeId.WattsPerSquareMeterKelvin, SymbolTypeId.WPerMSup2K);
                expectedTypesWinvKinvArea.AddExpectedType(1, SpecTypeId.HvacPower); // UT_Electrical_Wattage is similar, but UT_HVAC_Power is the one we map to.
                expectedTypesWinvKinvArea.AddExpectedType(-1, SpecTypeId.HvacTemperature);
                expectedTypesWinvKinvArea.AddExpectedType(-1, SpecTypeId.Area);
                expectedTypesList.Add(expectedTypesWinvKinvArea);

                DerivedUnitExpectedTypes expectedTypes = new DerivedUnitExpectedTypes(UnitTypeId.WattsPerSquareMeterKelvin, SymbolTypeId.WPerMSup2K);
                expectedTypes.AddExpectedType(1, SpecTypeId.Mass);
                expectedTypes.AddExpectedType(-1, SpecTypeId.HvacTemperature);
                expectedTypes.AddCustomExpectedType(-3, "TIMEUNIT");
                expectedTypesList.Add(expectedTypes);
            }
            else if (string.Compare(unitType, "VOLUMETRICFLOWRATEUNIT", true) == 0)
            {
                Spec       = SpecTypeId.AirFlow;
                UnitSystem = UnitSystem.Metric;

                // Support L / s or m^3 / s in the IFC file.

                // L / s
                DerivedUnitExpectedTypes expectedTypesLPerS = new DerivedUnitExpectedTypes(UnitTypeId.LitersPerSecond, SymbolTypeId.LPerS);
                expectedTypesLPerS.AddExpectedType(1, SpecTypeId.Volume);
                expectedTypesLPerS.AddCustomExpectedType(-1, "TIMEUNIT");
                expectedTypesList.Add(expectedTypesLPerS);

                // m^3 / s.
                DerivedUnitExpectedTypes expectedTypes = new DerivedUnitExpectedTypes(UnitTypeId.CubicMetersPerSecond, SymbolTypeId.MSup3PerS);
                expectedTypes.AddExpectedType(3, SpecTypeId.Length);
                expectedTypes.AddCustomExpectedType(-1, "TIMEUNIT");
                expectedTypesList.Add(expectedTypes);
            }
            else if (string.Compare(unitType, "MASSDENSITYUNIT", true) == 0)
            {
                Spec       = SpecTypeId.MassDensity;
                UnitSystem = UnitSystem.Metric;

                // Support kg / m^3 in the IFC file.

                // kg / m^3.
                DerivedUnitExpectedTypes expectedTypes = new DerivedUnitExpectedTypes(UnitTypeId.KilogramsPerCubicMeter, SymbolTypeId.KgPerMSup3);
                expectedTypes.AddExpectedType(1, SpecTypeId.Mass);
                expectedTypes.AddExpectedType(-3, SpecTypeId.Length);
                expectedTypesList.Add(expectedTypes);
            }
            else if (string.Compare(unitType, "LINEARFORCEUNIT", true) == 0)
            {
                Spec       = SpecTypeId.LinearForce;
                UnitSystem = UnitSystem.Metric;

                // Support N / m in the IFC file.
                DerivedUnitExpectedTypes expectedTypes = new DerivedUnitExpectedTypes(UnitTypeId.NewtonsPerMeter, SymbolTypeId.NPerM);
                expectedTypes.AddExpectedType(1, SpecTypeId.LinearForce);
                expectedTypesList.Add(expectedTypes);

                // Support N / m in basic units
                DerivedUnitExpectedTypes expectedTypes2 = new DerivedUnitExpectedTypes(UnitTypeId.NewtonsPerMeter, SymbolTypeId.NPerM);
                expectedTypes2.AddExpectedType(1, SpecTypeId.Mass);
                expectedTypes2.AddExpectedType(1, SpecTypeId.Length);
                expectedTypes2.AddCustomExpectedType(-2, "TIMEUNIT");
                expectedTypes2.AddExpectedType(-1, SpecTypeId.Length);
                expectedTypesList.Add(expectedTypes2);
            }
            else if (string.Compare(unitType, "PLANARFORCEUNIT", true) == 0)
            {
                Spec       = SpecTypeId.AreaForce;
                UnitSystem = UnitSystem.Metric;

                // Support N / m^2 in the IFC file.
                DerivedUnitExpectedTypes expectedTypes = new DerivedUnitExpectedTypes(UnitTypeId.NewtonsPerSquareMeter, SymbolTypeId.NPerMSup2);
                expectedTypes.AddExpectedType(1, SpecTypeId.AreaForce);
                expectedTypesList.Add(expectedTypes);

                // Support N / m in basic units
                DerivedUnitExpectedTypes expectedTypes2 = new DerivedUnitExpectedTypes(UnitTypeId.NewtonsPerSquareMeter, SymbolTypeId.NPerMSup2);
                expectedTypes2.AddExpectedType(1, SpecTypeId.Mass);
                expectedTypes2.AddExpectedType(1, SpecTypeId.Length);
                expectedTypes2.AddCustomExpectedType(-2, "TIMEUNIT");
                expectedTypes2.AddExpectedType(-2, SpecTypeId.Length);
                expectedTypesList.Add(expectedTypes2);
            }
            else if (string.Compare(unitType, "USERDEFINED", true) == 0)
            {
                // Look at the sub-types to see what we support.
                string userDefinedType = IFCImportHandleUtil.GetOptionalStringAttribute(unitHnd, "UserDefinedType", null);
                if (!string.IsNullOrWhiteSpace(userDefinedType))
                {
                    if (string.Compare(userDefinedType, "Luminous Efficacy", true) == 0)
                    {
                        Spec       = SpecTypeId.Efficacy;
                        UnitSystem = UnitSystem.Metric;

                        // Support only lm / W.
                        DerivedUnitExpectedTypes expectedTypes = new DerivedUnitExpectedTypes(UnitTypeId.LumensPerWatt, SymbolTypeId.LmPerW);
                        expectedTypes.AddExpectedType(-1, SpecTypeId.Mass);
                        expectedTypes.AddExpectedType(-2, SpecTypeId.Length);
                        expectedTypes.AddCustomExpectedType(3, "TIMEUNIT");
                        expectedTypes.AddExpectedType(1, SpecTypeId.LuminousFlux);
                        expectedTypesList.Add(expectedTypes);
                    }
                    else if (string.Compare(userDefinedType, "Friction Loss", true) == 0)
                    {
                        Spec       = SpecTypeId.HvacFriction;
                        UnitSystem = UnitSystem.Metric;

                        // Support only Pa / m.
                        DerivedUnitExpectedTypes expectedTypes = new DerivedUnitExpectedTypes(UnitTypeId.PascalsPerMeter, SymbolTypeId.PaPerM);
                        expectedTypes.AddExpectedType(-2, SpecTypeId.Length);
                        expectedTypes.AddExpectedType(1, SpecTypeId.Mass);
                        expectedTypes.AddCustomExpectedType(-2, "TIMEUNIT");
                        expectedTypesList.Add(expectedTypes);
                    }
                }
            }

            foreach (DerivedUnitExpectedTypes derivedUnitExpectedTypes in expectedTypesList)
            {
                double scaleFactor = 1.0;
                if (derivedUnitExpectedTypes.Matches(derivedElementUnitHnds, out scaleFactor))
                {
                    // Found a match.
                    Unit        = derivedUnitExpectedTypes.Unit;
                    Symbol      = derivedUnitExpectedTypes.Symbol;
                    ScaleFactor = scaleFactor;
                    return;
                }
            }

            Importer.TheLog.LogUnhandledUnitTypeError(unitHnd, unitType);
        }
        /// <summary>
        /// Processes IfcRepresentation attributes.
        /// </summary>
        /// <param name="ifcRepresentation">The IfcRepresentation handle.</param>
        override protected void Process(IFCAnyHandle ifcRepresentation)
        {
            base.Process(ifcRepresentation);

            IFCAnyHandle representationContext = IFCImportHandleUtil.GetRequiredInstanceAttribute(ifcRepresentation, "ContextOfItems", false);

            if (representationContext != null)
            {
                Context = IFCRepresentationContext.ProcessIFCRepresentationContext(representationContext);
            }

            string identifier = IFCImportHandleUtil.GetOptionalStringAttribute(ifcRepresentation, "RepresentationIdentifier", null);

            Identifier = GetRepresentationIdentifier(identifier, ifcRepresentation);

            Type = IFCImportHandleUtil.GetOptionalStringAttribute(ifcRepresentation, "RepresentationType", null);

            HashSet <IFCAnyHandle> items =
                IFCAnyHandleUtil.GetAggregateInstanceAttribute <HashSet <IFCAnyHandle> >(ifcRepresentation, "Items");

            LayerAssignment = IFCPresentationLayerAssignment.GetTheLayerAssignment(ifcRepresentation, true);

            foreach (IFCAnyHandle item in items)
            {
                IFCRepresentationItem repItem = null;
                try
                {
                    if (NotAllowedInRepresentation(item))
                    {
                        IFCEntityType entityType = IFCAnyHandleUtil.GetEntityType(item);
                        Importer.TheLog.LogWarning(item.StepId, "Ignoring unhandled representation item of type " + entityType.ToString() + " in " +
                                                   Identifier.ToString() + " representation.", true);
                        continue;
                    }

                    // Special processing for bounding boxes - only IfcBoundingBox allowed.
                    if (IFCAnyHandleUtil.IsSubTypeOf(item, IFCEntityType.IfcBoundingBox))
                    {
                        // Don't read in Box represenation unless options allow it.
                        if (IFCImportFile.TheFile.Options.ProcessBoundingBoxGeometry == IFCProcessBBoxOptions.Never)
                        {
                            Importer.TheLog.LogWarning(item.StepId, "BoundingBox not imported with ProcessBoundingBoxGeometry=Never", false);
                        }
                        else
                        {
                            if (BoundingBox != null)
                            {
                                Importer.TheLog.LogWarning(item.StepId, "Found second IfcBoundingBox representation item, ignoring.", false);
                                continue;
                            }
                            BoundingBox = ProcessBoundingBox(item);
                        }
                    }
                    else
                    {
                        repItem = IFCRepresentationItem.ProcessIFCRepresentationItem(item);
                    }
                }
                catch (Exception ex)
                {
                    Importer.TheLog.LogError(item.StepId, ex.Message, false);
                }
                if (repItem != null)
                {
                    RepresentationItems.Add(repItem);
                }
            }
        }
Пример #14
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);
                    }
                }
            }
        }
Пример #15
0
        /// <summary>
        /// Processes monetary unit.
        /// </summary>
        /// <param name="monetaryUnitHnd">The monetary unit handle.</param>
        void ProcessIFCMonetaryUnit(IFCAnyHandle monetaryUnitHnd)
        {
            string currencyType = (IFCImportFile.TheFile.SchemaVersion < IFCSchemaVersion.IFC4) ?
                                  IFCAnyHandleUtil.GetEnumerationAttribute(monetaryUnitHnd, "Currency") :
                                  IFCImportHandleUtil.GetOptionalStringAttribute(monetaryUnitHnd, "Currency", string.Empty);

            UnitType = UnitType.UT_Currency;
            UnitName = UnitName.DUT_CURRENCY;

            UnitSymbol = UnitSymbolType.UST_NONE;
            if ((string.Compare(currencyType, "CAD", true) == 0) ||
                (string.Compare(currencyType, "USD", true) == 0) ||
                (string.Compare(currencyType, "$", true) == 0))
            {
                UnitSymbol = UnitSymbolType.UST_DOLLAR;
            }
            else if ((string.Compare(currencyType, "EUR", true) == 0) ||
                     (string.Compare(currencyType, "€", true) == 0))
            {
                UnitSymbol = UnitSymbolType.UST_EURO_PREFIX;
            }
            else if ((string.Compare(currencyType, "GBP", true) == 0) ||
                     (string.Compare(currencyType, "£", true) == 0))
            {
                UnitSymbol = UnitSymbolType.UST_POUND;
            }
            else if (string.Compare(currencyType, "HKD", true) == 0)
            {
                UnitSymbol = UnitSymbolType.UST_CHINESE_HONG_KONG_SAR;
            }
            else if ((string.Compare(currencyType, "ICK", true) == 0) ||
                     (string.Compare(currencyType, "NOK", true) == 0) ||
                     (string.Compare(currencyType, "SEK", true) == 0))
            {
                UnitSymbol = UnitSymbolType.UST_KRONER;
            }
            else if (string.Compare(currencyType, "ILS", true) == 0)
            {
                UnitSymbol = UnitSymbolType.UST_SHEQEL;
            }
            else if ((string.Compare(currencyType, "JPY", true) == 0) ||
                     (string.Compare(currencyType, "¥", true) == 0))
            {
                UnitSymbol = UnitSymbolType.UST_YEN;
            }
            else if (string.Compare(currencyType, "KRW", true) == 0)
            {
                UnitSymbol = UnitSymbolType.UST_WON;
            }
            else if ((string.Compare(currencyType, "THB", true) == 0) ||
                     (string.Compare(currencyType, "฿", true) == 0))
            {
                UnitSymbol = UnitSymbolType.UST_BAHT;
            }
            else if (string.Compare(currencyType, "VND", true) == 0)
            {
                UnitSymbol = UnitSymbolType.UST_DONG;
            }
            else
            {
                Importer.TheLog.LogWarning(Id, "Unhandled type of currency: " + currencyType, true);
            }
        }
Пример #16
0
        /// <summary>
        /// Processes an IfcDerivedUnit.
        /// </summary>
        /// <param name="unitHnd">The unit handle.</param>
        void ProcessIFCDerivedUnit(IFCAnyHandle unitHnd)
        {
            List <IFCAnyHandle> elements =
                IFCAnyHandleUtil.GetAggregateInstanceAttribute <List <IFCAnyHandle> >(unitHnd, "Elements");

            IList <KeyValuePair <IFCUnit, int> > derivedElementUnitHnds = new List <KeyValuePair <IFCUnit, int> >();

            foreach (IFCAnyHandle subElement in elements)
            {
                IFCAnyHandle derivedElementUnitHnd = IFCImportHandleUtil.GetRequiredInstanceAttribute(subElement, "Unit", false);
                IFCUnit      subUnit = IFCAnyHandleUtil.IsNullOrHasNoValue(derivedElementUnitHnd) ? null : IFCUnit.ProcessIFCUnit(derivedElementUnitHnd);
                if (subUnit != null)
                {
                    bool found;
                    int  exponent = IFCImportHandleUtil.GetRequiredIntegerAttribute(subElement, "Exponent", out found);
                    if (found)
                    {
                        derivedElementUnitHnds.Add(new KeyValuePair <IFCUnit, int>(subUnit, exponent));
                    }
                }
            }

            // the DerivedUnitExpectedTypes object is a description of one possible set of base units for a particular derived unit.
            // The IList allows for possible different interpretations.  For example, Volumetric Flow Rate could be defined by m^3/s (length ^ 3 / time) or L/s (volume / time).
            IList <DerivedUnitExpectedTypes> expectedTypesList = new List <DerivedUnitExpectedTypes>();

            string unitType = IFCAnyHandleUtil.GetEnumerationAttribute(unitHnd, "UnitType");

            if (string.Compare(unitType, "LINEARVELOCITYUNIT", true) == 0)
            {
                UnitType   = UnitType.UT_HVAC_Velocity;
                UnitSystem = UnitSystem.Metric;

                // Support only m / s.
                DerivedUnitExpectedTypes expectedTypes = new DerivedUnitExpectedTypes(UnitName.DUT_METERS_PER_SECOND, UnitSymbolType.UST_M_PER_S);
                expectedTypes.AddExpectedType(1, UnitType.UT_Length);
                expectedTypes.AddCustomExpectedType(-1, "TIMEUNIT");
                expectedTypesList.Add(expectedTypes);
            }
            else if (string.Compare(unitType, "THERMALTRANSMITTANCEUNIT", true) == 0)
            {
                UnitType   = UnitType.UT_HVAC_CoefficientOfHeatTransfer;
                UnitSystem = UnitSystem.Metric;

                // Support W / (K * m^2) or kg / (K * s^3)
                DerivedUnitExpectedTypes expectedTypesWinvKinvM2 = new DerivedUnitExpectedTypes(UnitName.DUT_WATTS_PER_SQUARE_METER_KELVIN, UnitSymbolType.UST_WATT_PER_SQ_M_K);
                expectedTypesWinvKinvM2.AddExpectedType(1, UnitType.UT_HVAC_Power); // UT_Electrical_Wattage is similar, but UT_HVAC_Power is the one we map to.
                expectedTypesWinvKinvM2.AddExpectedType(-1, UnitType.UT_HVAC_Temperature);
                expectedTypesWinvKinvM2.AddExpectedType(-2, UnitType.UT_Length);
                expectedTypesList.Add(expectedTypesWinvKinvM2);

                DerivedUnitExpectedTypes expectedTypesWinvKinvArea = new DerivedUnitExpectedTypes(UnitName.DUT_WATTS_PER_SQUARE_METER_KELVIN, UnitSymbolType.UST_WATT_PER_SQ_M_K);
                expectedTypesWinvKinvArea.AddExpectedType(1, UnitType.UT_HVAC_Power); // UT_Electrical_Wattage is similar, but UT_HVAC_Power is the one we map to.
                expectedTypesWinvKinvArea.AddExpectedType(-1, UnitType.UT_HVAC_Temperature);
                expectedTypesWinvKinvArea.AddExpectedType(-1, UnitType.UT_Area);
                expectedTypesList.Add(expectedTypesWinvKinvArea);

                DerivedUnitExpectedTypes expectedTypes = new DerivedUnitExpectedTypes(UnitName.DUT_WATTS_PER_SQUARE_METER_KELVIN, UnitSymbolType.UST_WATT_PER_SQ_M_K);
                expectedTypes.AddExpectedType(1, UnitType.UT_Mass);
                expectedTypes.AddExpectedType(-1, UnitType.UT_HVAC_Temperature);
                expectedTypes.AddCustomExpectedType(-3, "TIMEUNIT");
                expectedTypesList.Add(expectedTypes);
            }
            else if (string.Compare(unitType, "VOLUMETRICFLOWRATEUNIT", true) == 0)
            {
                UnitType   = UnitType.UT_HVAC_Airflow;
                UnitSystem = UnitSystem.Metric;

                // Support L / s or m^3 / s in the IFC file.

                // L / s
                DerivedUnitExpectedTypes expectedTypesLPerS = new DerivedUnitExpectedTypes(UnitName.DUT_LITERS_PER_SECOND, UnitSymbolType.UST_L_PER_S);
                expectedTypesLPerS.AddExpectedType(1, UnitType.UT_Volume);
                expectedTypesLPerS.AddCustomExpectedType(-1, "TIMEUNIT");
                expectedTypesList.Add(expectedTypesLPerS);

                // m^3 / s.
                DerivedUnitExpectedTypes expectedTypes = new DerivedUnitExpectedTypes(UnitName.DUT_CUBIC_METERS_PER_SECOND, UnitSymbolType.UST_CU_M_PER_S);
                expectedTypes.AddExpectedType(3, UnitType.UT_Length);
                expectedTypes.AddCustomExpectedType(-1, "TIMEUNIT");
                expectedTypesList.Add(expectedTypes);
            }
            else if (string.Compare(unitType, "MASSDENSITYUNIT", true) == 0)
            {
                UnitType   = UnitType.UT_MassDensity;
                UnitSystem = UnitSystem.Metric;

                // Support kg / m^3 in the IFC file.

                // kg / m^3.
                DerivedUnitExpectedTypes expectedTypes = new DerivedUnitExpectedTypes(UnitName.DUT_KILOGRAMS_PER_CUBIC_METER, UnitSymbolType.UST_KG_PER_CU_M);
                expectedTypes.AddExpectedType(1, UnitType.UT_Mass);
                expectedTypes.AddExpectedType(-3, UnitType.UT_Length);
                expectedTypesList.Add(expectedTypes);
            }
            else if (string.Compare(unitType, "USERDEFINED", true) == 0)
            {
                // Look at the sub-types to see what we support.
                string userDefinedType = IFCImportHandleUtil.GetOptionalStringAttribute(unitHnd, "UserDefinedType", null);
                if (!string.IsNullOrWhiteSpace(userDefinedType))
                {
                    if (string.Compare(userDefinedType, "Luminous Efficacy", true) == 0)
                    {
                        UnitType   = UnitType.UT_Electrical_Efficacy;
                        UnitSystem = UnitSystem.Metric;

                        // Support only lm / W.
                        DerivedUnitExpectedTypes expectedTypes = new DerivedUnitExpectedTypes(UnitName.DUT_LUMENS_PER_WATT, UnitSymbolType.UST_LM_PER_W);
                        expectedTypes.AddExpectedType(-1, UnitType.UT_Mass);
                        expectedTypes.AddExpectedType(-2, UnitType.UT_Length);
                        expectedTypes.AddCustomExpectedType(3, "TIMEUNIT");
                        expectedTypes.AddExpectedType(1, UnitType.UT_Electrical_Luminous_Flux);
                        expectedTypesList.Add(expectedTypes);
                    }
                    else if (string.Compare(userDefinedType, "Friction Loss", true) == 0)
                    {
                        UnitType   = UnitType.UT_HVAC_Friction;
                        UnitSystem = UnitSystem.Metric;

                        // Support only Pa / m.
                        DerivedUnitExpectedTypes expectedTypes = new DerivedUnitExpectedTypes(UnitName.DUT_PASCALS_PER_METER, UnitSymbolType.UST_PASCAL_PER_M);
                        expectedTypes.AddExpectedType(-2, UnitType.UT_Length);
                        expectedTypes.AddExpectedType(1, UnitType.UT_Mass);
                        expectedTypes.AddCustomExpectedType(-2, "TIMEUNIT");
                        expectedTypesList.Add(expectedTypes);
                    }
                }
            }

            foreach (DerivedUnitExpectedTypes derivedUnitExpectedTypes in expectedTypesList)
            {
                double scaleFactor = 1.0;
                if (derivedUnitExpectedTypes.Matches(derivedElementUnitHnds, out scaleFactor))
                {
                    // Found a match.
                    UnitName    = derivedUnitExpectedTypes.UnitName;
                    UnitSymbol  = derivedUnitExpectedTypes.UnitSymbol;
                    ScaleFactor = scaleFactor;
                    return;
                }
            }

            Importer.TheLog.LogUnhandledUnitTypeError(unitHnd, unitType);
        }
Пример #17
0
        /// <summary>
        /// Processes IfcRepresentationContext attributes.
        /// </summary>
        /// <param name="ifcRepresentationContext">The IfcRepresentationContext handle.</param>
        override protected void Process(IFCAnyHandle ifcRepresentationContext)
        {
            base.Process(ifcRepresentationContext);

            Identifier = IFCImportHandleUtil.GetOptionalStringAttribute(ifcRepresentationContext, "ContextIdentifier", null);

            Type = IFCImportHandleUtil.GetOptionalStringAttribute(ifcRepresentationContext, "ContextType", null);

            if (IFCAnyHandleUtil.IsSubTypeOf(ifcRepresentationContext, IFCEntityType.IfcGeometricRepresentationContext))
            {
                bool found = false;
                CoordinateSpaceDimension = IFCImportHandleUtil.GetRequiredIntegerAttribute(ifcRepresentationContext, "CoordinateSpaceDimension", out found);
                if (!found)
                {
                    CoordinateSpaceDimension = 3; // Don't throw, just set to default 3D.
                }
                Precision = IFCImportHandleUtil.GetOptionalScaledLengthAttribute(ifcRepresentationContext, "Precision", IFCImportFile.TheFile.Document.Application.VertexTolerance);

                IFCAnyHandle worldCoordinateSystem = IFCImportHandleUtil.GetRequiredInstanceAttribute(ifcRepresentationContext, "WorldCoordinateSystem", false);
                if (!IFCAnyHandleUtil.IsNullOrHasNoValue(worldCoordinateSystem))
                {
                    WorldCoordinateSystem = IFCLocation.ProcessIFCAxis2Placement(worldCoordinateSystem);
                }
                else
                {
                    WorldCoordinateSystem = Transform.Identity;
                }

                bool isSubContext = IFCImportFile.TheFile.SchemaVersionAtLeast(IFCSchemaVersion.IFC2x2) &&
                                    IFCAnyHandleUtil.IsSubTypeOf(ifcRepresentationContext, IFCEntityType.IfcGeometricRepresentationSubContext);

                if (isSubContext)
                {
                    IFCAnyHandle parentContext = IFCImportHandleUtil.GetRequiredInstanceAttribute(ifcRepresentationContext, "ParentContext", true);
                    ParentContext = IFCRepresentationContext.ProcessIFCRepresentationContext(parentContext);
                    TrueNorth     = ParentContext.TrueNorth;
                }
                else
                {
                    // This used to fail for IfcGeometricRepresentationSubContext, because the TrueNorth attribute was derived from
                    // the IfcGeometricRepresentationContext, and the toolkit returned what seemed to be a valid handle that actually
                    // wasn't.  The code has now been rewritten to avoid this issue, but we will keep the try/catch block in case we
                    // were also catching other serious issues.
                    try
                    {
                        // By default, True North points in the Y-Direction.
                        IFCAnyHandle trueNorth = IFCImportHandleUtil.GetOptionalInstanceAttribute(ifcRepresentationContext, "TrueNorth");
                        if (!IFCAnyHandleUtil.IsNullOrHasNoValue(trueNorth))
                        {
                            TrueNorth = IFCPoint.ProcessNormalizedIFCDirection(trueNorth);
                        }
                        else
                        {
                            TrueNorth = XYZ.BasisY;
                        }
                    }
                    catch
                    {
                        TrueNorth = XYZ.BasisY;
                    }
                }

                if (isSubContext)
                {
                    TargetScale = IFCImportHandleUtil.GetOptionalPositiveRatioAttribute(ifcRepresentationContext, "TargetScale", 1.0);

                    TargetView = IFCEnums.GetSafeEnumerationAttribute <IFCGeometricProjection>(ifcRepresentationContext, "TargetView",
                                                                                               IFCGeometricProjection.NotDefined);

                    UserDefinedTargetView = IFCImportHandleUtil.GetOptionalStringAttribute(ifcRepresentationContext, "UserDefinedTargetView", null);
                }
            }
        }
Пример #18
0
        /// <summary>
        /// Processes monetary unit.
        /// </summary>
        /// <param name="monetaryUnitHnd">The monetary unit handle.</param>
        void ProcessIFCMonetaryUnit(IFCAnyHandle monetaryUnitHnd)
        {
            string currencyType = (IFCImportFile.TheFile.SchemaVersion < IFCSchemaVersion.IFC4) ?
                                  IFCAnyHandleUtil.GetEnumerationAttribute(monetaryUnitHnd, "Currency") :
                                  IFCImportHandleUtil.GetOptionalStringAttribute(monetaryUnitHnd, "Currency", string.Empty);

            Spec = SpecTypeId.Currency;
            Unit = UnitTypeId.Currency;

            Symbol = new ForgeTypeId();
            if ((string.Compare(currencyType, "CAD", true) == 0) ||
                (string.Compare(currencyType, "USD", true) == 0) ||
                (string.Compare(currencyType, "$", true) == 0))
            {
                Symbol = SymbolTypeId.UsDollar;
            }
            else if ((string.Compare(currencyType, "EUR", true) == 0) ||
                     (string.Compare(currencyType, "€", true) == 0))
            {
                Symbol = SymbolTypeId.EuroPrefix;
            }
            else if ((string.Compare(currencyType, "GBP", true) == 0) ||
                     (string.Compare(currencyType, "£", true) == 0))
            {
                Symbol = SymbolTypeId.UkPound;
            }
            else if (string.Compare(currencyType, "HKD", true) == 0)
            {
                Symbol = SymbolTypeId.ChineseHongKongDollar;
            }
            else if ((string.Compare(currencyType, "ICK", true) == 0) ||
                     (string.Compare(currencyType, "NOK", true) == 0) ||
                     (string.Compare(currencyType, "SEK", true) == 0))
            {
                Symbol = SymbolTypeId.Krone;
            }
            else if (string.Compare(currencyType, "ILS", true) == 0)
            {
                Symbol = SymbolTypeId.Shekel;
            }
            else if ((string.Compare(currencyType, "JPY", true) == 0) ||
                     (string.Compare(currencyType, "¥", true) == 0))
            {
                Symbol = SymbolTypeId.Yen;
            }
            else if (string.Compare(currencyType, "KRW", true) == 0)
            {
                Symbol = SymbolTypeId.Won;
            }
            else if ((string.Compare(currencyType, "THB", true) == 0) ||
                     (string.Compare(currencyType, "฿", true) == 0))
            {
                Symbol = SymbolTypeId.Baht;
            }
            else if (string.Compare(currencyType, "VND", true) == 0)
            {
                Symbol = SymbolTypeId.Dong;
            }
            else
            {
                Importer.TheLog.LogWarning(Id, "Unhandled type of currency: " + currencyType, true);
            }
        }
Пример #19
0
        /// <summary>
        /// Processes IfcGridAxis attributes.
        /// </summary>
        /// <param name="ifcGridAxis">The IfcGridAxis handle.</param>
        protected override void Process(IFCAnyHandle ifcGridAxis)
        {
            base.Process(ifcGridAxis);

            AxisTag = IFCImportHandleUtil.GetOptionalStringAttribute(ifcGridAxis, "AxisTag", null);
            if (AxisTag == null)
            {
                AxisTag = "Z"; // arbitrary; all Revit Grids have names.
            }
            IFCAnyHandle axisCurve = IFCImportHandleUtil.GetRequiredInstanceAttribute(ifcGridAxis, "AxisCurve", true);

            AxisCurve = IFCCurve.ProcessIFCCurve(axisCurve);

            bool found     = false;
            bool sameSense = IFCImportHandleUtil.GetRequiredBooleanAttribute(ifcGridAxis, "SameSense", out found);

            SameSense = found ? sameSense : true;

            // We are going to check if this grid axis is a vertical duplicate of any existing axis.
            // If so, we will throw an exception so that we don't create duplicate grids.
            // We will only initialize these values if we actually intend to use them below.
            IList <Curve> curves     = null;
            int           curveCount = 0;

            ElementId gridId = ElementId.InvalidElementId;

            if (Importer.TheCache.GridNameToElementMap.TryGetValue(AxisTag, out gridId))
            {
                Grid grid = IFCImportFile.TheFile.Document.GetElement(gridId) as Grid;
                if (grid != null)
                {
                    IList <Curve> otherCurves = new List <Curve>();
                    Curve         gridCurve   = grid.Curve;
                    if (gridCurve != null)
                    {
                        otherCurves.Add(gridCurve);
                        int matchingGridId = FindMatchingGrid(otherCurves, grid.Id.IntegerValue, ref curves, ref curveCount);

                        if (matchingGridId != -1)
                        {
                            Importer.TheCache.UseGrid(grid);
                            CreatedElementId = grid.Id;
                            return;
                        }
                    }
                }
            }

            IDictionary <string, IFCGridAxis> gridAxes = IFCImportFile.TheFile.IFCProject.GridAxes;
            IFCGridAxis gridAxis = null;

            if (gridAxes.TryGetValue(AxisTag, out gridAxis))
            {
                int matchingGridId = FindMatchingGrid(gridAxis, ref curves, ref curveCount);
                if (matchingGridId != -1)
                {
                    DuplicateAxisId = matchingGridId;
                    return;
                }
                else
                {
                    // Revit doesn't allow grid lines to have the same name.  If it isn't a duplicate, rename it.
                    // Note that this will mean that we may miss some "duplicate" grid lines because of the renaming.
                    AxisTag = MakeAxisTagUnique(AxisTag);
                }
            }

            gridAxes.Add(new KeyValuePair <string, IFCGridAxis>(AxisTag, this));
        }
        override protected void Process(IFCAnyHandle item)
        {
            base.Process(item);

            Name = IFCImportHandleUtil.GetOptionalStringAttribute(item, "Name", null);
        }
Пример #21
0
        /// <summary>
        /// Processes an IfcDerivedUnit.
        /// </summary>
        /// <param name="unitHnd">The unit handle.</param>
        void ProcessIFCDerivedUnit(IFCAnyHandle unitHnd)
        {
            List <IFCAnyHandle> elements =
                IFCAnyHandleUtil.GetAggregateInstanceAttribute <List <IFCAnyHandle> >(unitHnd, "Elements");

            IList <KeyValuePair <IFCUnit, int> > derivedElementUnitHnds = new List <KeyValuePair <IFCUnit, int> >();

            foreach (IFCAnyHandle subElement in elements)
            {
                IFCAnyHandle derivedElementUnitHnd = IFCImportHandleUtil.GetRequiredInstanceAttribute(subElement, "Unit", false);
                IFCUnit      subUnit = IFCAnyHandleUtil.IsNullOrHasNoValue(derivedElementUnitHnd) ? null : IFCUnit.ProcessIFCUnit(derivedElementUnitHnd);
                if (subUnit != null)
                {
                    bool found;
                    int  exponent = IFCImportHandleUtil.GetRequiredIntegerAttribute(subElement, "Exponent", out found);
                    if (found)
                    {
                        derivedElementUnitHnds.Add(new KeyValuePair <IFCUnit, int>(subUnit, exponent));
                    }
                }
            }

            ISet <Tuple <int, UnitType, string> > expectedTypes = new HashSet <Tuple <int, UnitType, string> >();

            string unitType = IFCAnyHandleUtil.GetEnumerationAttribute(unitHnd, "UnitType");

            if (string.Compare(unitType, "THERMALTRANSMITTANCEUNIT", true) == 0)
            {
                UnitType   = UnitType.UT_HVAC_CoefficientOfHeatTransfer;
                UnitSystem = UnitSystem.Metric;
                UnitName   = UnitName.DUT_WATTS_PER_SQUARE_METER_KELVIN;

                // Support only kg / (K * s^3).
                expectedTypes.Add(new Tuple <int, Autodesk.Revit.DB.UnitType, string>(1, UnitType.UT_Mass, null));
                expectedTypes.Add(new Tuple <int, Autodesk.Revit.DB.UnitType, string>(-1, UnitType.UT_HVAC_Temperature, null));
                expectedTypes.Add(new Tuple <int, Autodesk.Revit.DB.UnitType, string>(-3, UnitType.UT_Custom, "TIMEUNIT"));
            }
            else if (string.Compare(unitType, "VOLUMETRICFLOWRATEUNIT", true) == 0)
            {
                UnitType   = UnitType.UT_HVAC_Airflow;
                UnitSystem = UnitSystem.Metric;
                UnitName   = UnitName.DUT_CUBIC_METERS_PER_SECOND;

                // Support only m^3 / s.
                expectedTypes.Add(new Tuple <int, Autodesk.Revit.DB.UnitType, string>(3, UnitType.UT_Length, null));
                expectedTypes.Add(new Tuple <int, Autodesk.Revit.DB.UnitType, string>(-1, UnitType.UT_Custom, "TIMEUNIT"));
            }
            else if (string.Compare(unitType, "USERDEFINED", true) == 0)
            {
                // Look at the sub-types to see what we support.
                string userDefinedType = IFCImportHandleUtil.GetOptionalStringAttribute(unitHnd, "UserDefinedType", null);
                if (!string.IsNullOrWhiteSpace(userDefinedType))
                {
                    if (string.Compare(userDefinedType, "Luminous Efficacy", true) == 0)
                    {
                        UnitType   = UnitType.UT_Electrical_Efficacy;
                        UnitSystem = UnitSystem.Metric;
                        UnitName   = UnitName.DUT_LUMENS_PER_WATT;

                        // Support only lm / W.
                        expectedTypes.Add(new Tuple <int, Autodesk.Revit.DB.UnitType, string>(-1, UnitType.UT_Mass, null));
                        expectedTypes.Add(new Tuple <int, Autodesk.Revit.DB.UnitType, string>(-2, UnitType.UT_Length, null));
                        expectedTypes.Add(new Tuple <int, Autodesk.Revit.DB.UnitType, string>(3, UnitType.UT_Custom, "TIMEUNIT"));
                        expectedTypes.Add(new Tuple <int, Autodesk.Revit.DB.UnitType, string>(1, UnitType.UT_Electrical_Luminous_Flux, null));
                    }
                }
            }

            double scaleFactor = 1.0;

            if (derivedElementUnitHnds.Count == expectedTypes.Count)
            {
                foreach (KeyValuePair <IFCUnit, int> derivedElementUnitHnd in derivedElementUnitHnds)
                {
                    int dimensionality = derivedElementUnitHnd.Value;
                    Tuple <int, UnitType, string> currKey = new Tuple <int, UnitType, string>(dimensionality, derivedElementUnitHnd.Key.UnitType, derivedElementUnitHnd.Key.CustomUnitType);
                    if (expectedTypes.Contains(currKey))
                    {
                        expectedTypes.Remove(currKey);
                        scaleFactor *= Math.Pow(derivedElementUnitHnd.Key.ScaleFactor, dimensionality);
                    }
                    else
                    {
                        break;
                    }
                }

                // Found all supported units.
                if (expectedTypes.Count == 0)
                {
                    ScaleFactor = scaleFactor;
                    return;
                }
            }

            IFCImportFile.TheLog.LogUnhandledUnitTypeError(unitHnd, unitType);
        }