Exemplo n.º 1
0
        /// <summary>
        /// Get Symbol string for IfcConversionBasedUnit conversion unit
        /// </summary>
        /// <returns>String holding symbol</returns>
        public static string GetSymbol(this IfcConversionBasedUnit ifcConversionBasedUnit)
        {
            string name = ifcConversionBasedUnit.Name;

            if ((ifcConversionBasedUnit.UnitType == IfcUnitEnum.LENGTHUNIT) ||
                (ifcConversionBasedUnit.UnitType == IfcUnitEnum.AREAUNIT) ||
                (ifcConversionBasedUnit.UnitType == IfcUnitEnum.VOLUMEUNIT)
                )
            {
                string pow = string.Empty;
                if (ifcConversionBasedUnit.Dimensions.LengthExponent == 2) //area
                {
                    pow += '\u00B2';                                       //try unicode ((char)0x00B2)add ²
                }
                if (ifcConversionBasedUnit.Dimensions.LengthExponent == 3) //volume
                {
                    pow += '\u00B3';                                       //((char)0x00B3)add ³
                }
                if ((name.Contains("FEET")) || (name.Contains("FOOT")))
                {
                    return("ft" + pow);
                }

                if (name.Contains("INCH"))
                {
                    return("in" + pow);
                }

                return(name + pow);
            }
            else
            {
                return(name);
            }
        }
Exemplo n.º 2
0
 public void Reset()
 {
     Contacts.Clear();
     _ifcConversionBasedUnitYear  = null;
     _ifcConversionBasedUnitMonth = null;
     _ifcConversionBasedUnitWeek  = null;
     _secondUnit           = null;
     _dimensionalExponents = null;
     WorkBook = null;
 }
Exemplo n.º 3
0
 private static void SetConversionUnitsParameters(IModel model, IfcConversionBasedUnit unit, IfcLabel name,
                                                  IfcRatioMeasure ratio, IfcUnitEnum unitType, IfcSIUnitName siUnitName,
                                                  IfcSIPrefix?siUnitPrefix, IfcDimensionalExponents dimensions)
 {
     unit.Name             = name;
     unit.ConversionFactor = model.Instances.New <IfcMeasureWithUnit>();
     unit.ConversionFactor.ValueComponent = ratio;
     unit.ConversionFactor.UnitComponent  = model.Instances.New <IfcSIUnit>(s =>
     {
         s.UnitType = unitType;
         s.Name     = siUnitName;
         s.Prefix   = siUnitPrefix;
     });
     unit.Dimensions = dimensions;
 }
Exemplo n.º 4
0
        /// <summary>
        /// Set the week duration unit
        /// </summary>
        private void SetMinuteDurationUnit()
        {
            SetSecondUnit();

            IfcMeasureWithUnit minuteMeasure = Model.Instances.New <IfcMeasureWithUnit>(mwu =>
            {
                mwu.ValueComponent = new IfcReal(60); //not accurate week but take average
                mwu.UnitComponent  = _secondUnit;
            });
            IfcConversionBasedUnit minuteConBaseUnit = Model.Instances.New <IfcConversionBasedUnit>(s =>
            {
                s.UnitType         = IfcUnitEnum.TIMEUNIT;
                s.Name             = "Minute";
                s.Dimensions       = _dimensionalExponents;
                s.ConversionFactor = minuteMeasure;
            });

            //set context units
            _ifcConversionBasedUnitMinute = minuteConBaseUnit;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Set the Year Duration Unit
        /// </summary>
        private void SetYearDurationUnit()
        {
            SetSecondUnit();

            IfcMeasureWithUnit yearMeasure = Model.Instances.New <IfcMeasureWithUnit>(mwu =>
            {
                mwu.ValueComponent = new IfcReal(3.1536E7);
                mwu.UnitComponent  = _secondUnit;
            });
            IfcConversionBasedUnit yearConBaseUnit = Model.Instances.New <IfcConversionBasedUnit>(s =>
            {
                s.UnitType         = IfcUnitEnum.TIMEUNIT;
                s.Name             = "Year";
                s.Dimensions       = _dimensionalExponents;
                s.ConversionFactor = yearMeasure;
            });

            //set context units
            _ifcConversionBasedUnitYear = yearConBaseUnit;
        }
Exemplo n.º 6
0
        public static double GetPower(this IfcUnitAssignment ua, IfcUnitEnum unitType)
        {
            IfcSIUnit si = ua.Units.OfType <IfcSIUnit>().FirstOrDefault(u => u.UnitType == unitType);

            if (si != null && si.Prefix.HasValue)
            {
                return(si.Power());
            }
            else
            {
                IfcConversionBasedUnit cu =
                    ua.Units.OfType <IfcConversionBasedUnit>().FirstOrDefault(u => u.UnitType == unitType);
                if (cu != null)
                {
                    IfcMeasureWithUnit mu = cu.ConversionFactor;
                    IfcSIUnit          uc = mu.UnitComponent as IfcSIUnit;
                    //some BIM tools such as StruCAD write the conversion value out as a Length Measure
                    if (uc != null)
                    {
                        ExpressType et      = ((ExpressType)mu.ValueComponent);
                        double      cFactor = 1.0;
                        if (et.UnderlyingSystemType == typeof(double))
                        {
                            cFactor = (double)et.Value;
                        }
                        else if (et.UnderlyingSystemType == typeof(int))
                        {
                            cFactor = (double)((int)et.Value);
                        }
                        else if (et.UnderlyingSystemType == typeof(long))
                        {
                            cFactor = (double)((long)et.Value);
                        }

                        return(uc.Power() * cFactor);
                    }
                }
            }
            return(1.0);
        }
Exemplo n.º 7
0
        public static string GetLengthUnitName(this IfcUnitAssignment ua)
        {
            IfcSIUnit si = ua.Units.OfType <IfcSIUnit>().FirstOrDefault(u => u.UnitType == IfcUnitEnum.LENGTHUNIT);

            if (si != null)
            {
                if (si.Prefix.HasValue)
                {
                    return(string.Format("{0}{1}", si.Prefix.Value.ToString(), si.Name.ToString()));
                }
                else
                {
                    return(si.Name.ToString());
                }
            }
            else
            {
                IfcConversionBasedUnit cu =
                    ua.Units.OfType <IfcConversionBasedUnit>().FirstOrDefault(u => u.UnitType == IfcUnitEnum.LENGTHUNIT);
                if (cu != null)
                {
                    return(cu.Name);
                }
                else
                {
                    IfcConversionBasedUnit cbu =
                        ua.Units.OfType <IfcConversionBasedUnit>().FirstOrDefault(
                            u => u.UnitType == IfcUnitEnum.LENGTHUNIT);
                    if (cbu != null)
                    {
                        return(cbu.Name);
                    }
                }
            }
            return("");
        }
Exemplo n.º 8
0
        private static IfcConversionBasedUnit GetNewConversionUnit(IModel model, IfcUnitEnum unitType, ConversionBasedUnit unitEnum)
        {
            IfcConversionBasedUnit unit = model.Instances.New <IfcConversionBasedUnit>();

            unit.UnitType = unitType;

            switch (unitEnum)
            {
            case ConversionBasedUnit.INCH:
                SetConversionUnitsParameters(model, unit, "inch", 25.4, IfcUnitEnum.LENGTHUNIT, IfcSIUnitName.METRE,
                                             IfcSIPrefix.MILLI, GetLengthDimension(model));
                break;

            case ConversionBasedUnit.FOOT:
                SetConversionUnitsParameters(model, unit, "foot", 304.8, IfcUnitEnum.LENGTHUNIT, IfcSIUnitName.METRE,
                                             IfcSIPrefix.MILLI, GetLengthDimension(model));
                break;

            case ConversionBasedUnit.YARD:
                SetConversionUnitsParameters(model, unit, "yard", 914, IfcUnitEnum.LENGTHUNIT, IfcSIUnitName.METRE,
                                             IfcSIPrefix.MILLI, GetLengthDimension(model));
                break;

            case ConversionBasedUnit.MILE:
                SetConversionUnitsParameters(model, unit, "mile", 1609, IfcUnitEnum.LENGTHUNIT, IfcSIUnitName.METRE,
                                             null, GetLengthDimension(model));
                break;

            case ConversionBasedUnit.ACRE:
                SetConversionUnitsParameters(model, unit, "acre", 4046.86, IfcUnitEnum.AREAUNIT,
                                             IfcSIUnitName.SQUARE_METRE, null, GetAreaDimension(model));
                break;

            case ConversionBasedUnit.LITRE:
                SetConversionUnitsParameters(model, unit, "litre", 0.001, IfcUnitEnum.VOLUMEUNIT,
                                             IfcSIUnitName.CUBIC_METRE, null, GetVolumeDimension(model));
                break;

            case ConversionBasedUnit.PINT_UK:
                SetConversionUnitsParameters(model, unit, "pint UK", 0.000568, IfcUnitEnum.VOLUMEUNIT,
                                             IfcSIUnitName.CUBIC_METRE, null, GetVolumeDimension(model));
                break;

            case ConversionBasedUnit.PINT_US:
                SetConversionUnitsParameters(model, unit, "pint US", 0.000473, IfcUnitEnum.VOLUMEUNIT,
                                             IfcSIUnitName.CUBIC_METRE, null, GetVolumeDimension(model));
                break;

            case ConversionBasedUnit.GALLON_UK:
                SetConversionUnitsParameters(model, unit, "gallon UK", 0.004546, IfcUnitEnum.VOLUMEUNIT,
                                             IfcSIUnitName.CUBIC_METRE, null, GetVolumeDimension(model));
                break;

            case ConversionBasedUnit.GALLON_US:
                SetConversionUnitsParameters(model, unit, "gallon US", 0.003785, IfcUnitEnum.VOLUMEUNIT,
                                             IfcSIUnitName.CUBIC_METRE, null, GetVolumeDimension(model));
                break;

            case ConversionBasedUnit.OUNCE:
                SetConversionUnitsParameters(model, unit, "ounce", 28.35, IfcUnitEnum.MASSUNIT, IfcSIUnitName.GRAM,
                                             null, GetMassDimension(model));
                break;

            case ConversionBasedUnit.POUND:
                SetConversionUnitsParameters(model, unit, "pound", 0.454, IfcUnitEnum.MASSUNIT, IfcSIUnitName.GRAM,
                                             IfcSIPrefix.KILO, GetMassDimension(model));
                break;

            case ConversionBasedUnit.SQUARE_FOOT:
                SetConversionUnitsParameters(model, unit, "square foot", 92903.04, IfcUnitEnum.AREAUNIT, IfcSIUnitName.METRE,
                                             IfcSIPrefix.MILLI, GetAreaDimension(model));
                break;

            case ConversionBasedUnit.CUBIC_FOOT:
                SetConversionUnitsParameters(model, unit, "cubic foot", 28316846.6, IfcUnitEnum.VOLUMEUNIT, IfcSIUnitName.METRE,
                                             IfcSIPrefix.MILLI, GetVolumeDimension(model));
                break;
            }

            return(unit);
        }
Exemplo n.º 9
0
        private static void Main(string[] args)
        {
            var database = new DatabaseIfc(ModelView.Ifc4X3NotAssigned);

            database.Factory.ApplicationDeveloper = "Sebastian Esser";
            // turn owner history off
            database.Factory.Options.GenerateOwnerHistory = false;

            // basic setup
            var site    = new IfcSite(database, "SiteA");
            var project = new IfcProject(
                site,
                "SampleProject with a span annotation",
                IfcUnitAssignment.Length.Metre
                );

            // create an annotation
            var annotation = new IfcAnnotation(database)
            {
                Name = "DesignSpeed",
            };

            annotation.AddComment("Annotation item span-placed along the alignment");

            // link annotation with site
            var contained = new IfcRelContainedInSpatialStructure(site);

            contained.RelatedElements.Add(annotation);

            #region Alignment

            var alignment = new IfcAlignment(site)
            {
                Name = "Basic alignment with a single horizontal segment"
            };
            alignment.AddComment("Generate alignment representation");

            // semantic
            var horizSegment = new IfcAlignmentHorizontalSegment(
                new IfcCartesianPoint(database, 5, 10),
                0,
                0,
                0,
                200,
                IfcAlignmentHorizontalSegmentTypeEnum.LINE);

            // geometric representation of a single segment. It gets referenced by IfcCompositeCurve.segments and IfcAlignmentSegment.Representation
            var curveSegment = new IfcCurveSegment(
                IfcTransitionCode.CONTSAMEGRADIENTSAMECURVATURE,
                new IfcAxis2Placement2D(new IfcCartesianPoint(database, 0, 0)),
                new IfcParameterValue(0),
                new IfcParameterValue(200),
                null);


            var segments = new List <IfcSegment> {
                curveSegment
            };
            var compositeCurve = new IfcCompositeCurve(segments);

            var rep = new IfcShapeRepresentation(compositeCurve)
            {
                RepresentationIdentifier = "Axis",
                RepresentationType       = "Curve2D"
            };

            alignment.Representation = new IfcProductDefinitionShape(rep);
            alignment.Axis           = compositeCurve;

            // create an alignment horizontal instance that takes a list of horizontal segments
            var alignmentHorizontal = new IfcAlignmentHorizontal(database)
            {
                Segments = new LIST <IfcAlignmentHorizontalSegment>()
                {
                    horizSegment
                }
            };

            // link alignment and and its horizontal part semantically
            new IfcRelAggregates(alignment, alignmentHorizontal);

            // create a new alignmentSegment with then gets one curve segment as its geometric representation
            var alignmentSegment = new IfcAlignmentSegment(database);

            // link horizontal alignment with the recently created alignment segment
            new IfcRelNests(alignmentHorizontal, alignmentSegment); // sorted list -> IfcRelNests

            // connect geom representation to this segment
            alignmentSegment.Representation = new IfcProductDefinitionShape(new IfcShapeRepresentation(curveSegment));

            #endregion Alignment

            #region Annotation placement

            alignmentSegment.AddComment("Create placement for annotation");

            var axis2place = new IfcAxis2PlacementLinear(
                new IfcPointByDistanceExpression(25, compositeCurve),
                null,
                null);

            var linPlacement = new IfcLinearPlacement(axis2place);
            linPlacement.Distance      = new IfcPointByDistanceExpression(128, compositeCurve);
            annotation.ObjectPlacement = linPlacement;

            #endregion Annotation placement

            #region PSet

            //var lengthUnit = new IfcSIUnit(database, IfcUnitEnum.LENGTHUNIT, IfcSIPrefix.NONE, IfcSIUnitName.METRE);

            var lengthDerivedUnit = new IfcSIUnit(database, IfcUnitEnum.LENGTHUNIT, IfcSIPrefix.KILO, IfcSIUnitName.METRE);
            lengthDerivedUnit.AddComment("PSet setup");
            var timeBaseUnit    = new IfcSIUnit(database, IfcUnitEnum.TIMEUNIT, IfcSIPrefix.NONE, IfcSIUnitName.SECOND);
            var timeDerivedUnit = new IfcConversionBasedUnit(IfcUnitEnum.TIMEUNIT, "hour", new IfcMeasureWithUnit(new IfcPositiveInteger(3600), timeBaseUnit));

            var ifcderivedunitelem1 = new IfcDerivedUnitElement(lengthDerivedUnit, 1);
            var ifcderivedunitelem2 = new IfcDerivedUnitElement(timeDerivedUnit, -1);
            var speedUnit           = new IfcDerivedUnit(
                new List <IfcDerivedUnitElement> {
                ifcderivedunitelem1, ifcderivedunitelem2
            },
                IfcDerivedUnitEnum.LINEARVELOCITYUNIT);

            var pSet = new IfcPropertySet(annotation, "PSET_SpeedData", new List <IfcProperty>
            {
                new IfcPropertySingleValue(database, "CargoSpeed", new IfcLinearVelocityMeasure(60), speedUnit),
                new IfcPropertySingleValue(database, "DesignSpeed", new IfcLinearVelocityMeasure(110), speedUnit)
            });

            #endregion PSet

            database.WriteFile("AlignmentWithSpanAnnotation.ifc");
        }
Exemplo n.º 10
0
        public Model(IDictionary <Guid, BaseIfc> storage, string name, string description, IfcAddress address, IfcPerson user, IfcOrganization owner)
        {
            this.storage = storage;

            this.storage.Add(address.Id, address);
            this.storage.Add(user.Id, user);
            this.storage.Add(owner.Id, owner);

            // Create an organization for app creation.
            var appOrg = new IfcOrganization(APPNAME);

            this.storage.Add(appOrg.Id, appOrg);

            // Create an authoring application.
            var v   = owner.GetType().Assembly.GetName().Version.ToString();
            var app = new IfcApplication(appOrg, v, APPNAME, APPNAME);

            this.storage.Add(app.Id, app);

            // Create an person and history for the owner history.
            var personAndOrg = new IfcPersonAndOrganization(user, owner);

            this.storage.Add(personAndOrg.Id, personAndOrg);

            // Create an owner history for the project.
            var history = new IfcOwnerHistory(personAndOrg, app, UnixNow());

            this.storage.Add(history.Id, history);

            var lu = new IfcSIUnit(null, IfcUnitEnum.LENGTHUNIT, IfcSIUnitName.METRE);

            this.storage.Add(lu.Id, lu);
            var lengthUnit = new IfcUnit(lu);

            var au = new IfcSIUnit(null, IfcUnitEnum.AREAUNIT, IfcSIUnitName.SQUARE_METRE);

            this.storage.Add(au.Id, au);
            var areaUnit = new IfcUnit(au);

            var vu = new IfcSIUnit(null, IfcUnitEnum.VOLUMEUNIT, IfcSIUnitName.CUBIC_METRE);

            this.storage.Add(vu.Id, vu);
            var volumeUnit = new IfcUnit(vu);

            var sau = new IfcSIUnit(null, IfcUnitEnum.SOLIDANGLEUNIT, IfcSIUnitName.STERADIAN);

            this.storage.Add(sau.Id, sau);
            var solidAngleUnit = new IfcUnit(sau);

            var mu = new IfcSIUnit(null, IfcUnitEnum.MASSUNIT, IfcSIUnitName.GRAM);

            this.storage.Add(mu.Id, mu);
            var massUnit = new IfcUnit(mu);

            var tu = new IfcSIUnit(null, IfcUnitEnum.TIMEUNIT, IfcSIUnitName.SECOND);

            this.storage.Add(tu.Id, tu);
            var timeUnit = new IfcUnit(tu);

            var thu = new IfcSIUnit(null, IfcUnitEnum.THERMODYNAMICTEMPERATUREUNIT, IfcSIUnitName.DEGREE_CELSIUS);

            this.storage.Add(thu.Id, thu);
            var thermUnit = new IfcUnit(thu);

            var lmu = new IfcSIUnit(null, IfcUnitEnum.LUMINOUSINTENSITYUNIT, IfcSIUnitName.LUMEN);

            this.storage.Add(lmu.Id, lmu);
            var lumUnit = new IfcUnit(lmu);

            var pau = new IfcSIUnit(null, IfcUnitEnum.PLANEANGLEUNIT, IfcSIUnitName.RADIAN);

            this.storage.Add(pau.Id, pau);
            var planeAngleUnit = new IfcUnit(pau);

            var measure = new IfcMeasureWithUnit(new IfcValue(new IfcMeasureValue(new IfcPlaneAngleMeasure(1.745e-2))), planeAngleUnit);

            this.storage.Add(measure.Id, measure);

            var dimExp = new IfcDimensionalExponents(0, 0, 0, 0, 0, 0, 0);

            this.storage.Add(dimExp.Id, dimExp);

            var du = new IfcConversionBasedUnit(dimExp, IfcUnitEnum.PLANEANGLEUNIT, "DEGREE", measure);

            this.storage.Add(du.Id, du);
            var degree = new IfcUnit(du);

            var units = new List <IfcUnit> {
                lengthUnit, areaUnit, volumeUnit, solidAngleUnit, massUnit, timeUnit, thermUnit, lumUnit, planeAngleUnit, degree
            };
            var unitAss = new IfcUnitAssignment(units);

            this.storage.Add(unitAss.Id, unitAss);

            // Create the project.
            var proj = new IfcProject(IfcGuid.ToIfcGuid(Guid.NewGuid()), history, name, description, null, null, null, null, unitAss);

            this.storage.Add(proj.Id, proj);
        }
Exemplo n.º 11
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="bbUnitBase"></param>
        public void SetUnit(
             BbUnit bbUnitBase)
        {
            _bbUnit = bbUnitBase;
            IfcUnitAssignment = new IfcUnitAssignment { Units = new List<IfcUnit>() };
            switch (_bbUnit)
            {
                case BbUnit.Metric:
                    #region metric

                    IfcUnitAssignment.Units.Add(
                        new IfcUnit
                        {
                            Value = new IfcSIUnit(
                                IfcUnitEnum.LENGTHUNIT, IfcSIPrefix.MILLI, IfcSIUnitName.METRE)
                        });
                    IfcUnitAssignment.Units.Add(
                        new IfcUnit
                        {
                            Value = new IfcSIUnit(
                                IfcUnitEnum.AREAUNIT, IfcSIUnitName.SQUARE_METRE)
                        });
                    IfcUnitAssignment.Units.Add(
                        new IfcUnit
                        {
                            Value = new IfcSIUnit(
                                IfcUnitEnum.VOLUMEUNIT, IfcSIUnitName.CUBIC_METRE)
                        });

                    #endregion
                    break;
                case BbUnit.Imperial:
                    #region imperial
                    var leng = new IfcConversionBasedUnit
                    {
                        Dimensions = new IfcDimensionalExponents
                        {
                            LengthExponent = 1,
                            MassExponent = 0,
                            TimeExponent = 0,
                            ElectricCurrentExponent = 0,
                            ThermodynamicTemperatureExponent = 0,
                            AmountOfSubstanceExponent = 0,
                            LuminousIntensityExponent = 0,
                        },
                        UnitType = IfcUnitEnum.LENGTHUNIT,
                        Name = "FOOT",
                        ConversionFactor = new IfcMeasureWithUnit
                        {
                            ValueComponent = new IfcValue
                            {
                                Value = new IfcRatioMeasure { Value = 0.3048 }
                            },
                            UnitComponent = new IfcUnit { Value = new IfcSIUnit(IfcUnitEnum.LENGTHUNIT, IfcSIUnitName.METRE) }
                        }
                    };
                    var length = new IfcUnit { Value = leng };
                    IfcUnitAssignment.Units.Add(length);

                    var area = new IfcConversionBasedUnit
                    {
                        Dimensions = new IfcDimensionalExponents
                        {
                            LengthExponent = 2,
                            MassExponent = 0,
                            TimeExponent = 0,
                            ElectricCurrentExponent = 0,
                            ThermodynamicTemperatureExponent = 0,
                            AmountOfSubstanceExponent = 0,
                            LuminousIntensityExponent = 0,
                        },
                        UnitType = IfcUnitEnum.AREAUNIT,
                        Name = "SQUARE FOOT",
                        ConversionFactor = new IfcMeasureWithUnit
                        {
                            ValueComponent = new IfcValue
                            {
                                Value
                                = new IfcRatioMeasure { Value = 0.09290304 }
                            },
                            UnitComponent = new IfcUnit { Value = new IfcSIUnit(IfcUnitEnum.AREAUNIT, IfcSIUnitName.SQUARE_METRE) }
                        }
                    };

                    var areaUnit = new IfcUnit { Value = area };
                    IfcUnitAssignment.Units.Add(areaUnit);

                    var volume = new IfcConversionBasedUnit
                    {
                        Dimensions = new IfcDimensionalExponents
                        {
                            LengthExponent = 3,
                            MassExponent = 0,
                            TimeExponent = 0,
                            ElectricCurrentExponent = 0,
                            ThermodynamicTemperatureExponent = 0,
                            AmountOfSubstanceExponent = 0,
                            LuminousIntensityExponent = 0,

                        },
                        UnitType = IfcUnitEnum.VOLUMEUNIT,
                        Name = "CUBIC FOOT",
                        ConversionFactor = new IfcMeasureWithUnit
                        {
                            ValueComponent = new IfcValue
                            {
                                Value = new IfcRatioMeasure { Value = 0.02831685 }
                            },
                            UnitComponent = new IfcUnit { Value = new IfcSIUnit(IfcUnitEnum.VOLUMEUNIT, IfcSIUnitName.CUBIC_METRE) }
                        }
                    };

                    var volumeUnit = new IfcUnit { Value = volume };
                    IfcUnitAssignment.Units.Add(volumeUnit);
                    #endregion
                    break;
            }

            var degree = new IfcConversionBasedUnit
            {
                Dimensions = new IfcDimensionalExponents
                {
                    LengthExponent = 0,
                    MassExponent = 0,
                    TimeExponent = 0,
                    ElectricCurrentExponent = 0,
                    ThermodynamicTemperatureExponent = 0,
                    AmountOfSubstanceExponent = 0,
                    LuminousIntensityExponent = 0,
                },
                UnitType = IfcUnitEnum.PLANEANGLEUNIT,
                Name = "DEGREE",
                ConversionFactor = new IfcMeasureWithUnit
                {
                    ValueComponent = new IfcValue
                    {
                        Value = new IfcPlaneAngleMeasure
                        {
                            Value = 0.01745329
                        }
                    },
                    UnitComponent = new IfcUnit
                    {
                        Value = new IfcSIUnit(IfcUnitEnum.PLANEANGLEUNIT, IfcSIUnitName.RADIAN)
                    }
                }
            };
            var angle = new IfcUnit { Value = degree };
            IfcUnitAssignment.Units.Add(angle);

            IfcUnitAssignment.Units.Add(
                new IfcUnit()
                {
                    Value = new IfcSIUnit(IfcUnitEnum.SOLIDANGLEUNIT, IfcSIUnitName.STERADIAN)
                });
            IfcUnitAssignment.Units.Add(
                new IfcUnit()
                {
                    Value = new IfcSIUnit(IfcUnitEnum.MASSUNIT, IfcSIUnitName.GRAM)
                });
            IfcUnitAssignment.Units.Add(
                new IfcUnit()
                {
                    Value = new IfcSIUnit(IfcUnitEnum.TIMEUNIT, IfcSIUnitName.SECOND)
                });
            IfcUnitAssignment.Units.Add(
                new IfcUnit()
                {
                    Value = new IfcSIUnit(IfcUnitEnum.THERMODYNAMICTEMPERATUREUNIT, IfcSIUnitName.DEGREE_CELSIUS)
                });
            IfcUnitAssignment.Units.Add(
                new IfcUnit()
                {
                    Value = new IfcSIUnit(IfcUnitEnum.LUMINOUSINTENSITYUNIT, IfcSIUnitName.LUMEN)
                });
        }
Exemplo n.º 12
0
        /// <summary>
        /// Extract the unit name
        /// </summary>
        /// <param name="ifcUnit">ifcUnit object to get unit name from</param>
        /// <returns>string holding unit name</returns>
        public static string GetUnitName(IfcUnit ifcUnit)
        {
            string value      = "";
            string sqText     = "";
            string prefixUnit = "";

            if (ifcUnit is IfcSIUnit)
            {
                IfcSIUnit ifcSIUnit = ifcUnit as IfcSIUnit;

                prefixUnit = (ifcSIUnit.Prefix != null) ? ifcSIUnit.Prefix.ToString() : "";  //see IfcSIPrefix
                value      = ifcSIUnit.Name.ToString();                                      //see IfcSIUnitName

                if (!string.IsNullOrEmpty(value))
                {
                    if (value.Contains("_"))
                    {
                        string[] split = value.Split('_');
                        if (split.Length > 1)
                        {
                            sqText = split.First();                 //see if _ delimited value such as SQUARE_METRE
                        }
                        value = sqText + prefixUnit + split.Last(); //combine to give full unit name
                    }
                    else
                    {
                        value = prefixUnit + value; //combine to give length name
                    }
                }
            }
            else if (ifcUnit is IfcConversionBasedUnit)
            {
                IfcConversionBasedUnit IfcConversionBasedUnit = ifcUnit as IfcConversionBasedUnit;
                value = (IfcConversionBasedUnit.Name != null) ? IfcConversionBasedUnit.Name.ToString() : "";

                if (!string.IsNullOrEmpty(value))
                {
                    if (value.Contains("_"))
                    {
                        string[] split = value.Split('_');
                        if (split.Length > 1)
                        {
                            sqText = split.First();    //see if _ delimited value such as SQUARE_METRE
                        }
                        value = sqText + split.Last(); //combine to give full unit name
                    }
                }
            }
            else if (ifcUnit is IfcContextDependentUnit)
            {
                IfcContextDependentUnit ifcContextDependentUnit = ifcUnit as IfcContextDependentUnit;
                value = ifcContextDependentUnit.Name;
                if (string.IsNullOrEmpty(value)) //fall back to UnitType enumeration
                {
                    value = ifcContextDependentUnit.UnitType.ToString();
                }
            }
            else if (ifcUnit is IfcDerivedUnit)
            {
                IfcDerivedUnit ifcDerivedUnit = ifcUnit as IfcDerivedUnit;
                value = ifcDerivedUnit.UnitType.ToString();
                if ((string.IsNullOrEmpty(value)) && (ifcDerivedUnit.UserDefinedType != null)) //fall back to user defined
                {
                    value = ifcDerivedUnit.UserDefinedType;
                }
            }
            else if (ifcUnit is IfcMonetaryUnit)
            {
                value = GetMonetaryUnitName(ifcUnit as IfcMonetaryUnit);
                return((string.IsNullOrEmpty(value)) ? DEFAULT_STRING : value); //don't want to lower case so return here
            }
            value = (string.IsNullOrEmpty(value)) ? DEFAULT_STRING : value.ToLower();

            //check for unit spelling on meter/metre
            if (value.Contains("metre") || value.Contains("meter"))
            {
                string culturemetre = ErrorDescription.meter;
                if (!string.IsNullOrEmpty(culturemetre))
                {
                    if (value.Contains("metre"))
                    {
                        value = value.Replace("metre", culturemetre);
                    }
                    else
                    {
                        value = value.Replace("meter", culturemetre);
                    }
                }
            }
            return(value);
        }
Exemplo n.º 13
0
        private static void CreateElementQuantity(XbimModel model, IfcWallStandardCase wall, IfcOwnerHistory ifcOwnerHistory)
        {
            //Create a IfcElementQuantity
            //first we need a IfcPhysicalSimpleQuantity,first will use IfcQuantityArea
            IfcQuantityArea ifcQuantityArea = model.Instances.New <IfcQuantityArea>(qa =>
            {
                qa.Name        = "IfcQuantityArea:Area";
                qa.Description = "";
                qa.Unit        = model.Instances.New <IfcSIUnit>(siu =>
                {
                    siu.UnitType   = IfcUnitEnum.AREAUNIT;
                    siu.Prefix     = IfcSIPrefix.MILLI;
                    siu.Name       = IfcSIUnitName.SQUARE_METRE;
                    siu.Dimensions = model.Instances.New <IfcDimensionalExponents>(de =>
                    {
                        de.LengthExponent                   = 1;
                        de.MassExponent                     = 0;
                        de.TimeExponent                     = 0;
                        de.ElectricCurrentExponent          = 0;
                        de.ThermodynamicTemperatureExponent = 0;
                        de.AmountOfSubstanceExponent        = 0;
                        de.LuminousIntensityExponent        = 0;
                    });
                });
                qa.AreaValue = 100.0;
            });
            //next quantity IfcQuantityCount using IfcContextDependentUnit
            IfcContextDependentUnit ifcContextDependentUnit = model.Instances.New <IfcContextDependentUnit>(cd =>
            {
                cd.Dimensions = model.Instances.New <IfcDimensionalExponents>(de =>
                {
                    de.LengthExponent                   = 1;
                    de.MassExponent                     = 0;
                    de.TimeExponent                     = 0;
                    de.ElectricCurrentExponent          = 0;
                    de.ThermodynamicTemperatureExponent = 0;
                    de.AmountOfSubstanceExponent        = 0;
                    de.LuminousIntensityExponent        = 0;
                });
                cd.UnitType = IfcUnitEnum.LENGTHUNIT;
                cd.Name     = "Elephants";
            });
            IfcQuantityCount ifcQuantityCount = model.Instances.New <IfcQuantityCount>(qc =>
            {
                qc.Name       = "IfcQuantityCount:Elephant";
                qc.CountValue = 12;
                qc.Unit       = ifcContextDependentUnit;
            });


            //next quantity IfcQuantityLength using IfcConversionBasedUnit
            IfcConversionBasedUnit ifcConversionBasedUnit = model.Instances.New <IfcConversionBasedUnit>(cbu =>
            {
                cbu.ConversionFactor = model.Instances.New <IfcMeasureWithUnit>(mu =>
                {
                    mu.ValueComponent = new IfcRatioMeasure(25.4);
                    mu.UnitComponent  = model.Instances.New <IfcSIUnit>(siu =>
                    {
                        siu.UnitType = IfcUnitEnum.LENGTHUNIT;
                        siu.Prefix   = IfcSIPrefix.MILLI;
                        siu.Name     = IfcSIUnitName.METRE;
                    });
                });
                cbu.Dimensions = model.Instances.New <IfcDimensionalExponents>(de =>
                {
                    de.LengthExponent                   = 1;
                    de.MassExponent                     = 0;
                    de.TimeExponent                     = 0;
                    de.ElectricCurrentExponent          = 0;
                    de.ThermodynamicTemperatureExponent = 0;
                    de.AmountOfSubstanceExponent        = 0;
                    de.LuminousIntensityExponent        = 0;
                });
                cbu.UnitType = IfcUnitEnum.LENGTHUNIT;
                cbu.Name     = "Inch";
            });
            IfcQuantityLength ifcQuantityLength = model.Instances.New <IfcQuantityLength>(qa =>
            {
                qa.Name        = "IfcQuantityLength:Length";
                qa.Description = "";
                qa.Unit        = ifcConversionBasedUnit;
                qa.LengthValue = 24.0;
            });

            //lets create the IfcElementQuantity
            IfcElementQuantity ifcElementQuantity = model.Instances.New <IfcElementQuantity>(eq =>
            {
                eq.OwnerHistory = ifcOwnerHistory;
                eq.Name         = "Test:IfcElementQuantity";
                eq.Description  = "Measurement quantity";
                eq.Quantities.Add(ifcQuantityArea);
                eq.Quantities.Add(ifcQuantityCount);
                eq.Quantities.Add(ifcQuantityLength);
            });

            //need to create the relationship
            IfcRelDefinesByProperties ifcRelDefinesByProperties = model.Instances.New <IfcRelDefinesByProperties>(rdbp =>
            {
                rdbp.OwnerHistory = ifcOwnerHistory;
                rdbp.Name         = "Area Association";
                rdbp.Description  = "IfcElementQuantity associated to wall";
                rdbp.RelatedObjects.Add(wall);
                rdbp.RelatingPropertyDefinition = ifcElementQuantity;
            });
        }
Exemplo n.º 14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="bbUnitBase"></param>
        public void SetUnit(
            BbUnit bbUnitBase)
        {
            _bbUnit           = bbUnitBase;
            IfcUnitAssignment = new IfcUnitAssignment {
                Units = new List <IfcUnit>()
            };
            switch (_bbUnit)
            {
            case BbUnit.Metric:
                #region metric

                IfcUnitAssignment.Units.Add(
                    new IfcUnit
                {
                    Value = new IfcSIUnit(
                        IfcUnitEnum.LENGTHUNIT, IfcSIPrefix.MILLI, IfcSIUnitName.METRE)
                });
                IfcUnitAssignment.Units.Add(
                    new IfcUnit
                {
                    Value = new IfcSIUnit(
                        IfcUnitEnum.AREAUNIT, IfcSIUnitName.SQUARE_METRE)
                });
                IfcUnitAssignment.Units.Add(
                    new IfcUnit
                {
                    Value = new IfcSIUnit(
                        IfcUnitEnum.VOLUMEUNIT, IfcSIUnitName.CUBIC_METRE)
                });

                #endregion
                break;

            case BbUnit.Imperial:
                #region imperial
                var leng = new IfcConversionBasedUnit
                {
                    Dimensions = new IfcDimensionalExponents
                    {
                        LengthExponent                   = 1,
                        MassExponent                     = 0,
                        TimeExponent                     = 0,
                        ElectricCurrentExponent          = 0,
                        ThermodynamicTemperatureExponent = 0,
                        AmountOfSubstanceExponent        = 0,
                        LuminousIntensityExponent        = 0,
                    },
                    UnitType         = IfcUnitEnum.LENGTHUNIT,
                    Name             = "FOOT",
                    ConversionFactor = new IfcMeasureWithUnit
                    {
                        ValueComponent = new IfcValue
                        {
                            Value = new IfcRatioMeasure {
                                Value = 0.3048
                            }
                        },
                        UnitComponent = new IfcUnit {
                            Value = new IfcSIUnit(IfcUnitEnum.LENGTHUNIT, IfcSIUnitName.METRE)
                        }
                    }
                };
                var length = new IfcUnit {
                    Value = leng
                };
                IfcUnitAssignment.Units.Add(length);

                var area = new IfcConversionBasedUnit
                {
                    Dimensions = new IfcDimensionalExponents
                    {
                        LengthExponent                   = 2,
                        MassExponent                     = 0,
                        TimeExponent                     = 0,
                        ElectricCurrentExponent          = 0,
                        ThermodynamicTemperatureExponent = 0,
                        AmountOfSubstanceExponent        = 0,
                        LuminousIntensityExponent        = 0,
                    },
                    UnitType         = IfcUnitEnum.AREAUNIT,
                    Name             = "SQUARE FOOT",
                    ConversionFactor = new IfcMeasureWithUnit
                    {
                        ValueComponent = new IfcValue
                        {
                            Value
                                = new IfcRatioMeasure {
                                Value = 0.09290304
                                }
                        },
                        UnitComponent = new IfcUnit {
                            Value = new IfcSIUnit(IfcUnitEnum.AREAUNIT, IfcSIUnitName.SQUARE_METRE)
                        }
                    }
                };

                var areaUnit = new IfcUnit {
                    Value = area
                };
                IfcUnitAssignment.Units.Add(areaUnit);

                var volume = new IfcConversionBasedUnit
                {
                    Dimensions = new IfcDimensionalExponents
                    {
                        LengthExponent                   = 3,
                        MassExponent                     = 0,
                        TimeExponent                     = 0,
                        ElectricCurrentExponent          = 0,
                        ThermodynamicTemperatureExponent = 0,
                        AmountOfSubstanceExponent        = 0,
                        LuminousIntensityExponent        = 0,
                    },
                    UnitType         = IfcUnitEnum.VOLUMEUNIT,
                    Name             = "CUBIC FOOT",
                    ConversionFactor = new IfcMeasureWithUnit
                    {
                        ValueComponent = new IfcValue
                        {
                            Value = new IfcRatioMeasure {
                                Value = 0.02831685
                            }
                        },
                        UnitComponent = new IfcUnit {
                            Value = new IfcSIUnit(IfcUnitEnum.VOLUMEUNIT, IfcSIUnitName.CUBIC_METRE)
                        }
                    }
                };

                var volumeUnit = new IfcUnit {
                    Value = volume
                };
                IfcUnitAssignment.Units.Add(volumeUnit);
                #endregion
                break;
            }

            var degree = new IfcConversionBasedUnit
            {
                Dimensions = new IfcDimensionalExponents
                {
                    LengthExponent                   = 0,
                    MassExponent                     = 0,
                    TimeExponent                     = 0,
                    ElectricCurrentExponent          = 0,
                    ThermodynamicTemperatureExponent = 0,
                    AmountOfSubstanceExponent        = 0,
                    LuminousIntensityExponent        = 0,
                },
                UnitType         = IfcUnitEnum.PLANEANGLEUNIT,
                Name             = "DEGREE",
                ConversionFactor = new IfcMeasureWithUnit
                {
                    ValueComponent = new IfcValue
                    {
                        Value = new IfcPlaneAngleMeasure
                        {
                            Value = 0.01745329
                        }
                    },
                    UnitComponent = new IfcUnit
                    {
                        Value = new IfcSIUnit(IfcUnitEnum.PLANEANGLEUNIT, IfcSIUnitName.RADIAN)
                    }
                }
            };
            var angle = new IfcUnit {
                Value = degree
            };
            IfcUnitAssignment.Units.Add(angle);

            IfcUnitAssignment.Units.Add(
                new IfcUnit()
            {
                Value = new IfcSIUnit(IfcUnitEnum.SOLIDANGLEUNIT, IfcSIUnitName.STERADIAN)
            });
            IfcUnitAssignment.Units.Add(
                new IfcUnit()
            {
                Value = new IfcSIUnit(IfcUnitEnum.MASSUNIT, IfcSIUnitName.GRAM)
            });
            IfcUnitAssignment.Units.Add(
                new IfcUnit()
            {
                Value = new IfcSIUnit(IfcUnitEnum.TIMEUNIT, IfcSIUnitName.SECOND)
            });
            IfcUnitAssignment.Units.Add(
                new IfcUnit()
            {
                Value = new IfcSIUnit(IfcUnitEnum.THERMODYNAMICTEMPERATUREUNIT, IfcSIUnitName.DEGREE_CELSIUS)
            });
            IfcUnitAssignment.Units.Add(
                new IfcUnit()
            {
                Value = new IfcSIUnit(IfcUnitEnum.LUMINOUSINTENSITYUNIT, IfcSIUnitName.LUMEN)
            });
        }