コード例 #1
0
        private static IfcDerivedUnit AddIfcDerivedUnit(
                                        Ifc4.Document document,
                                        Unit unit,
                                        IfcDerivedUnit ifcDerivedUnit
                                    )
        {

            if (document.Project.UnitsInContext == null)
                document.Project.UnitsInContext = new IfcUnitAssignment();
            var ifcUnitAssignment = document.Project.UnitsInContext;

            if (ifcUnitAssignment.Units == null)
                ifcUnitAssignment.Units = new IfcUnitAssignmentUnits();
            var ifcUnitAssignmentUnits = ifcUnitAssignment.Units;

            ifcUnitAssignmentUnits.Items.Add(ifcDerivedUnit);
            return ifcDerivedUnit;
        }
コード例 #2
0
 /// <summary>
 /// Get the full name of the IfcDerivedUnit
 /// </summary>
 /// <returns>string holding full name</returns>
 public static string GetName(this IfcDerivedUnit ifcDerivedUnit)
 {
     if (ifcDerivedUnit.UserDefinedType.HasValue)
     {
         return(ifcDerivedUnit.UserDefinedType);
     }
     else
     {
         List <string> values = new List <string>();
         foreach (IfcDerivedUnitElement item in ifcDerivedUnit.Elements)//loop the units associated to this type
         {
             string value = string.Empty;
             value = item.Unit.GetName();
             //add power
             if (item.Exponent > 0)
             {
                 if (item.Exponent == 2)
                 {
                     value += '\u00B2';//add ² ((char)0x00B2)
                 }
                 else if (item.Exponent == 3)
                 {
                     value += '\u00B3';//add ³  //((char)0x00B3)
                 }
                 else
                 {
                     value += "Pow:" + item.Exponent.ToString();
                 }
             }
         }
         if (values.Count > 1)
         {
             return(string.Join("/", values));
         }
         else
         {
             return(string.Empty);
         }
     }
 }
コード例 #3
0
        internal Entity AddUnitToIfcDocument(Ifc4.Document document, Ifc4.Unit unit)
        {
            if (document == null)
                throw new ArgumentNullException("AddUnitToIfcDocument(Ifc4.Document document, ...)");

            if (unit == null)
                throw new ArgumentNullException("AddUnitToIfcDocument(..., Unit unit)");

            Entity entity = null;

            if (unit.Key == "m")
            {
                entity = AddIfcSIUnit(document, unit, IfcUnitEnum.Lengthunit, null, IfcSIUnitName.Metre);
            }
            else if (unit.Key == "dm")
            {
                entity = AddIfcSIUnit(document, unit, IfcUnitEnum.Lengthunit, IfcSIPrefix.Deci, IfcSIUnitName.Metre);
            }
            else if (unit.Key == "cm")
            {
                entity = AddIfcSIUnit(document, unit, IfcUnitEnum.Lengthunit, IfcSIPrefix.Centi, IfcSIUnitName.Metre);
            }
            else if (unit.Key == "mm")
            {
                entity = AddIfcSIUnit(document, unit, IfcUnitEnum.Lengthunit, IfcSIPrefix.Milli, IfcSIUnitName.Metre);
            }
            else if (unit.Key == "m²")
            {
                entity = AddIfcSIUnit(document, unit, IfcUnitEnum.Areaunit, null, IfcSIUnitName.SquareMetre);
            }
            else if (unit.Key == "dm²")
            {
                entity = AddIfcSIUnit(document, unit, IfcUnitEnum.Areaunit, IfcSIPrefix.Deci, IfcSIUnitName.SquareMetre);
            }
            else if (unit.Key == "cm²")
            {
                entity = AddIfcSIUnit(document, unit, IfcUnitEnum.Areaunit, IfcSIPrefix.Centi, IfcSIUnitName.SquareMetre);
            }
            else if (unit.Key == "mm²")
            {
                entity = AddIfcSIUnit(document, unit, IfcUnitEnum.Areaunit, IfcSIPrefix.Milli, IfcSIUnitName.SquareMetre);
            }
            else if (unit.Key == "m³")
            {
                entity = AddIfcSIUnit(document, unit, IfcUnitEnum.Volumeunit, null, IfcSIUnitName.CubicMetre);
            }
            else if (unit.Key == "dm³")
            {
                entity = AddIfcSIUnit(document, unit, IfcUnitEnum.Volumeunit, IfcSIPrefix.Deci, IfcSIUnitName.CubicMetre);
            }
            else if (unit.Key == "cm³")
            {
                entity = AddIfcSIUnit(document, unit, IfcUnitEnum.Volumeunit, IfcSIPrefix.Centi, IfcSIUnitName.CubicMetre);
            }
            else if (unit.Key == "mm³")
            {
                entity = AddIfcSIUnit(document, unit, IfcUnitEnum.Volumeunit, IfcSIPrefix.Milli, IfcSIUnitName.CubicMetre);
            }
            // 1Liter = 1dm³
            // 1m³ = 1000dm³
            else if (unit.Key == "l" || unit.Key == "Liter")
            {
                entity = AddIfcSIUnit(document, unit, IfcUnitEnum.Volumeunit, IfcSIPrefix.Deci, IfcSIUnitName.CubicMetre);
            }
            else if (unit.Key == "V")
            {
                entity = AddIfcSIUnit(document, unit, IfcUnitEnum.Electricvoltageunit, null, IfcSIUnitName.Volt);
            }
            else if (unit.Key == "J")
            {
                entity = AddIfcSIUnit(document, unit, IfcUnitEnum.Energyunit, null, IfcSIUnitName.Joule);
            }
            else if (unit.Key == "°C")
            {
                entity = AddIfcSIUnit(document, unit, IfcUnitEnum.Thermodynamictemperatureunit, null, IfcSIUnitName.DegreeCelsius);
            }
            else if (unit.Key == "A")
            {
                entity = AddIfcSIUnit(document, unit, IfcUnitEnum.Electriccurrentunit, null, IfcSIUnitName.Ampere);
            }
            else if (unit.Key == "Hz") // 1/s
            {
                entity = AddIfcSIUnit(document, unit, IfcUnitEnum.Frequencyunit, null, IfcSIUnitName.Hertz);
            }
            else if (unit.Key == "N")
            {
                entity = AddIfcSIUnit(document, unit, IfcUnitEnum.Forceunit, null, IfcSIUnitName.Newton);
            }
            else if (unit.Key == "kg")
            {
                entity = AddIfcSIUnit(document, unit, IfcUnitEnum.Massunit, IfcSIPrefix.Kilo, IfcSIUnitName.Gram);
            }
            else if (unit.Key == "g")
            {
                entity = AddIfcSIUnit(document, unit, IfcUnitEnum.Massunit, null, IfcSIUnitName.Gram);
            }
            else if (unit.Key == "s")
            {
                entity = AddIfcSIUnit(document, unit, IfcUnitEnum.Timeunit, null, IfcSIUnitName.Second);
            }
            else if (unit.Key == "m/s")
            {
                IfcDerivedUnit ifcDerivedUnit = new IfcDerivedUnit()
                {
                    Id = document.GetNextSid(),
                    UnitType = IfcDerivedUnitEnum.Linearvelocityunit,
                    UnitTypeSpecified = true,
                    Elements = new IfcDerivedUnitElements()
                };

                ifcDerivedUnit.Elements.IfcDerivedUnitElement.AddRange(
                    new IfcDerivedUnitElement[]
                        {
                            new IfcDerivedUnitElement()
                            {
                                Id = document.GetNextSid(),
                                Exponent = 1,
                                ExponentSpecified = true,
                                Unit = new IfcSIUnit()
                                {
                                    UnitType = IfcUnitEnum.Lengthunit,
                                    UnitTypeSpecified = true,
                                }
                            },
                            new IfcDerivedUnitElement()
                            {
                                Id = document.GetNextSid(),
                                Exponent = -1,
                                ExponentSpecified = true,
                                Unit = new IfcSIUnit()
                                {
                                    UnitType = IfcUnitEnum.Timeunit,
                                    UnitTypeSpecified = true,
                                }
                            }
                        }
                    );

                entity = AddIfcDerivedUnit(document, unit, ifcDerivedUnit);
            }
            else if (unit.Key == "m/s²")
            {
                IfcDerivedUnit ifcDerivedUnit = new IfcDerivedUnit()
                {
                    Id = document.GetNextSid(),
                    UnitType = IfcDerivedUnitEnum.Accelerationunit,
                    UnitTypeSpecified = true,
                    Elements = new IfcDerivedUnitElements()
                };

                ifcDerivedUnit.Elements.IfcDerivedUnitElement.AddRange(
                    new IfcDerivedUnitElement[]
                        {
                            new IfcDerivedUnitElement()
                            {
                                Id = document.GetNextSid(),
                                Exponent = 1,
                                ExponentSpecified = true,
                                Unit = new IfcSIUnit()
                                {
                                    UnitType = IfcUnitEnum.Lengthunit,
                                    UnitTypeSpecified = true,
                                }
                            },
                            new IfcDerivedUnitElement()
                            {
                                Id = document.GetNextSid(),
                                Exponent = -2,
                                ExponentSpecified = true,
                                Unit = new IfcSIUnit
                                {
                                    UnitType = IfcUnitEnum.Timeunit,
                                    UnitTypeSpecified = true,
                                }
                            }
                        }
                    );

                entity = AddIfcDerivedUnit(document, unit, ifcDerivedUnit);
            }
            else if (unit.Key == "m³/h")
            {
                IfcDerivedUnit ifcDerivedUnit = new IfcDerivedUnit()
                {
                    Id = document.GetNextSid(),
                    UnitType = IfcDerivedUnitEnum.Volumetricflowrateunit,
                    UnitTypeSpecified = true,
                    Elements = new IfcDerivedUnitElements()
                };

                ifcDerivedUnit.Elements.IfcDerivedUnitElement.AddRange(
                    new IfcDerivedUnitElement[]
                        {
                            new IfcDerivedUnitElement()
                            {
                                Id = document.GetNextSid(),
                                Exponent = 3,
                                ExponentSpecified = true,
                                Unit = new IfcSIUnit()
                                {
                                    UnitType = IfcUnitEnum.Lengthunit,
                                    UnitTypeSpecified = true
                                }
                            },
                            new IfcDerivedUnitElement()
                            {
                                Id = document.GetNextSid(),
                                Exponent = -1,
                                ExponentSpecified = true,
                                Unit = new IfcConversionBasedUnit
                                {
                                    Name = "Hour",
                                    UnitType = IfcUnitEnum.Timeunit,
                                    UnitTypeSpecified = true,
                                    ConversionFactor = new IfcMeasureWithUnit()
                                    {
                                        ValueComponent = new IfcMeasureWithUnitValueComponent()
                                        {
                                            Item = new IfcTimeMeasurewrapper()
                                            {
                                                Value = 3600.0
                                            }
                                        },
                                        UnitComponent = new IfcMeasureWithUnitUnitComponent()
                                        {
                                            Item = new IfcSIUnit()
                                            {
                                                UnitType = IfcUnitEnum.Timeunit,
                                                UnitTypeSpecified = true
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    );
                entity = AddIfcDerivedUnit(document, unit, ifcDerivedUnit);
            }
            else if (unit.Key == "Ah")
            {
                IfcDerivedUnit ifcDerivedUnit = new IfcDerivedUnit()
                {
                    Id = document.GetNextSid(),
                    UnitType = IfcDerivedUnitEnum.Heatfluxdensityunit,
                    UnitTypeSpecified = true,
                    Elements = new IfcDerivedUnitElements()
                };

                ifcDerivedUnit.Elements.IfcDerivedUnitElement.AddRange(
                    new IfcDerivedUnitElement[]
                        {
                            new IfcDerivedUnitElement()
                            {
                                Id = document.GetNextSid(),
                                Exponent = 1,
                                ExponentSpecified = true,
                                Unit = new IfcSIUnit()
                                {
                                    UnitType = IfcUnitEnum.Electriccurrentunit,
                                    UnitTypeSpecified = true
                                }
                            },
                            new IfcDerivedUnitElement()
                            {
                                Id = document.GetNextSid(),
                                Exponent = -1,
                                ExponentSpecified = true,
                                Unit = new IfcConversionBasedUnit
                                {
                                    Name = "Hour",
                                    UnitType = IfcUnitEnum.Timeunit,
                                    UnitTypeSpecified = true,
                                    ConversionFactor = new IfcMeasureWithUnit()
                                    {
                                        ValueComponent = new IfcMeasureWithUnitValueComponent()
                                        {
                                            Item = new IfcTimeMeasurewrapper()
                                            {
                                                Value = 3600.0
                                            }
                                        },
                                        UnitComponent = new IfcMeasureWithUnitUnitComponent()
                                        {
                                            Item = new IfcSIUnit()
                                            {
                                                UnitType = IfcUnitEnum.Timeunit,
                                                UnitTypeSpecified = true
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    );
                entity = AddIfcDerivedUnit(document, unit, ifcDerivedUnit);
            }
            else if (unit.Key == "Ohm")
            {
                entity = AddIfcSIUnit(document, unit, IfcUnitEnum.Electricresistanceunit, null, IfcSIUnitName.Ohm);
            }
            else if (unit.Key == "kg/m³")
            {
                IfcDerivedUnit ifcDerivedUnit = new IfcDerivedUnit()
                {
                    Id = document.GetNextSid(),
                    UnitType = IfcDerivedUnitEnum.Massdensityunit,
                    UnitTypeSpecified = true,
                    Elements = new IfcDerivedUnitElements()
                };

                ifcDerivedUnit.Elements.IfcDerivedUnitElement.AddRange(
                    new IfcDerivedUnitElement[]
                        {
                            new IfcDerivedUnitElement()
                            {
                                Id = document.GetNextSid(),
                                Exponent = 1,
                                ExponentSpecified = true,
                                Unit = new IfcSIUnit()
                                {
                                    UnitType = IfcUnitEnum.Massunit,
                                    UnitTypeSpecified = true,
                                }
                            },
                            new IfcDerivedUnitElement()
                            {
                                Id = document.GetNextSid(),
                                Exponent = -3,
                                ExponentSpecified = true,
                                Unit = new IfcSIUnit
                                {
                                    UnitType = IfcUnitEnum.Lengthunit,
                                    UnitTypeSpecified = true,
                                }
                            }
                        }
                    );
                entity = AddIfcDerivedUnit(document, unit, ifcDerivedUnit);
            }
            else if (unit.Key == "N/m²")
            {
                IfcDerivedUnit ifcDerivedUnit = new IfcDerivedUnit()
                {
                    Id = document.GetNextSid(),
                    UnitType = IfcDerivedUnitEnum.Planarforceunit,
                    UnitTypeSpecified = true,
                    Elements = new IfcDerivedUnitElements()
                };

                ifcDerivedUnit.Elements.IfcDerivedUnitElement.AddRange(
                    new IfcDerivedUnitElement[]
                        {
                            new IfcDerivedUnitElement()
                            {
                                Id = document.GetNextSid(),
                                Exponent = 1,
                                ExponentSpecified = true,
                                Unit = new IfcSIUnit()
                                {
                                    UnitType = IfcUnitEnum.Forceunit,
                                    UnitTypeSpecified = true,
                                }
                            },
                            new IfcDerivedUnitElement()
                            {
                                Id = document.GetNextSid(),
                                Exponent = -2,
                                ExponentSpecified = true,
                                Unit = new IfcSIUnit()
                                {
                                    UnitType = IfcUnitEnum.Lengthunit,
                                    UnitTypeSpecified = true,
                                }
                            }
                        }
                    );
                entity = AddIfcDerivedUnit(document, unit, ifcDerivedUnit);
            }
            else if (unit.Key == "W/m²")
            {
                IfcDerivedUnit ifcDerivedUnit = new IfcDerivedUnit()
                {
                    Id = document.GetNextSid(),
                    UnitType = IfcDerivedUnitEnum.Heatfluxdensityunit,
                    UnitTypeSpecified = true,
                    Elements = new IfcDerivedUnitElements()
                };

                ifcDerivedUnit.Elements.IfcDerivedUnitElement.AddRange(
                    new IfcDerivedUnitElement[]
                        {
                            new IfcDerivedUnitElement()
                            {
                                Id = document.GetNextSid(),
                                Exponent = 1,
                                ExponentSpecified = true,
                                Unit = new IfcSIUnit()
                                {
                                    UnitType = IfcUnitEnum.Powerunit,
                                    UnitTypeSpecified = true,
                                }
                            },
                            new IfcDerivedUnitElement()
                            {
                                Id = document.GetNextSid(),
                                Exponent = -2,
                                ExponentSpecified = true,
                                Unit = new IfcSIUnit
                                {
                                    UnitType = IfcUnitEnum.Lengthunit,
                                    UnitTypeSpecified = true,
                                }
                            }
                        }
                    );
                entity = AddIfcDerivedUnit(document, unit, ifcDerivedUnit);
            }
            else if (unit.Key == "W")
            {
                entity = AddIfcSIUnit(document, unit, IfcUnitEnum.Powerunit, null, IfcSIUnitName.Watt);
            }
            else if (unit.Key == "kW")
            {
                entity = AddIfcSIUnit(document, unit, IfcUnitEnum.Powerunit, IfcSIPrefix.Kilo, IfcSIUnitName.Watt);
            }
            else if (unit.Key == "Pa")
            {
                entity = AddIfcSIUnit(document, unit, IfcUnitEnum.Pressureunit, null, IfcSIUnitName.Pascal);
            }
            else if (unit.Key == "db")
            {
                IfcDerivedUnit ifcDerivedUnit = new IfcDerivedUnit()
                {
                    Id = document.GetNextSid(),
                    UnitType = IfcDerivedUnitEnum.Soundpowerlevelunit,
                    UnitTypeSpecified = true,
                    Elements = new IfcDerivedUnitElements()
                };

                ifcDerivedUnit.Elements.IfcDerivedUnitElement.AddRange(
                    new IfcDerivedUnitElement[]
                        {
                            new IfcDerivedUnitElement()
                            {
                                Id = document.GetNextSid(),
                                Exponent = 1,
                                ExponentSpecified = true,
                                Unit = new IfcSIUnit()
                                {
                                    UnitType = IfcUnitEnum.Powerunit,
                                    UnitTypeSpecified = true,
                                }
                            },
                            new IfcDerivedUnitElement()
                            {
                                Id = document.GetNextSid(),
                                Exponent = -1,
                                ExponentSpecified = true,
                                Unit = new IfcSIUnit
                                {
                                    UnitType = IfcUnitEnum.Powerunit,
                                    UnitTypeSpecified = true,
                                }
                            }
                        }
                    );
                entity = AddIfcDerivedUnit(document, unit, ifcDerivedUnit);
            }

            if (entity == null)
                throw new NullReferenceException("AddUnitToIfcDocument -  Entity = null");

            return entity;

        }
コード例 #4
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");
        }
コード例 #5
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);
        }
コード例 #6
0
 /// <summary>
 /// Get the html version of the Derived unit
 /// </summary>
 /// <param name="ifcDerivedUnit">IfcDerivedUnit to get name for</param>
 /// <returns>String holding name</returns>
 public static string GetDerivedUnitName(IfcDerivedUnit ifcDerivedUnit)
 {
     string unit = string.Empty;
     if (ifcDerivedUnit.UserDefinedType.HasValue)
         unit = ifcDerivedUnit.UserDefinedType;
     else
     {
         List<string> values = new List<string>();
         foreach (IfcDerivedUnitElement item in ifcDerivedUnit.Elements)//loop the units associated to this type
         {
             string value = string.Empty;
             value = item.Unit.GetName();
             //add power
             if (item.Exponent > 0)
             {
                 value += "<sup>" + item.Exponent.ToString() + "</sup>";
             }
         }
         if (values.Count > 1)
             unit = string.Join("/", values);
         else
             unit = string.Empty;
     }
     return unit;
 }