Ejemplo n.º 1
0
        /// <summary>
        /// Set the area measure to the building
        /// </summary>
        /// <param name="ifcBuilding">Building object</param>
        /// <param name="row">COBieFacilityRow object holding data</param>
        private void SetAreaMeasure(IfcBuilding ifcBuilding, COBieFacilityRow row)
        {
            IfcSIUnit ifcSIUnitArea = null;

            if (ValidateString(row.AreaUnits))
            {
                ifcSIUnitArea = GetSIUnit(row.AreaUnits);
            }
            string areaMeasure = string.Empty;

            if (ValidateString(row.AreaMeasurement))
            {
                areaMeasure = row.AreaMeasurement;
            }

            IfcQuantityArea IfcQuantityArea = Model.Instances.New <IfcQuantityArea>(qa =>
            {
                qa.Unit        = ifcSIUnitArea;
                qa.Name        = "AreaMeasure";
                qa.Description = "Created to maintain COBie information";
            });
            IfcElementQuantity ifcElementQuantity = Model.Instances.New <IfcElementQuantity>(eq =>
            {
                eq.Quantities.Add(IfcQuantityArea);
                eq.MethodOfMeasurement = areaMeasure;
                eq.Description         = "Created to maintain COBie information";
            });
            IfcRelDefinesByProperties ifcRelDefinesByProperties = Model.Instances.New <IfcRelDefinesByProperties>(rdbp =>
            {
                rdbp.RelatedObjects.Add(ifcBuilding);
                rdbp.RelatingPropertyDefinition = ifcElementQuantity;
                rdbp.Description = "Created to maintain COBie information";
            });
        }
Ejemplo n.º 2
0
        /// <summary>
        /// set the second unit, used for time duration units
        /// </summary>
        private void SetSecondUnit()
        {
            if (_secondUnit == null)
            {
                _secondUnit = Model.Instances.New <IfcSIUnit>(si =>
                {
                    si.UnitType = IfcUnitEnum.TIMEUNIT;
                    si.Prefix   = null;
                    si.Name     = IfcSIUnitName.SECOND;
                });
            }

            if (_dimensionalExponents == null)
            {
                _dimensionalExponents = Model.Instances.New <IfcDimensionalExponents>(de =>
                {
                    de.LengthExponent                   = 1;
                    de.MassExponent                     = 1;
                    de.TimeExponent                     = 1;
                    de.ElectricCurrentExponent          = 1;
                    de.ThermodynamicTemperatureExponent = 1;
                    de.AmountOfSubstanceExponent        = 1;
                    de.LuminousIntensityExponent        = 1;
                });
            }
        }
Ejemplo n.º 3
0
 public void Reset()
 {
     Contacts.Clear();
     _ifcConversionBasedUnitYear  = null;
     _ifcConversionBasedUnitMonth = null;
     _ifcConversionBasedUnitWeek  = null;
     _secondUnit           = null;
     _dimensionalExponents = null;
     WorkBook = null;
 }
Ejemplo n.º 4
0
        public SIUnit(IfcStore model, IfcSIUnitName name, IfcUnitEnum unitType)
        {
            ifcSiUnit = model.Instances.New <IfcSIUnit>(p =>
            {
                p.Name     = name;
                p.UnitType = unitType;
            });

            this.name     = name;
            this.unitType = unitType;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Get Symbol string for SIUnit unit
        /// </summary>
        /// <returns>String holding symbol</returns>
        public static string GetSymbol(this IfcSIUnit ifcSIUnit)
        {
            IfcSIUnitName ifcSIUnitName = ifcSIUnit.Name;
            IfcSIPrefix   ifcSIPrefix;
            string        value  = string.Empty;
            string        prefix = string.Empty;

            if (ifcSIUnit.Prefix != null)
            {
                ifcSIPrefix = (IfcSIPrefix)ifcSIUnit.Prefix;
                switch (ifcSIPrefix)
                {
                case IfcSIPrefix.CENTI:
                    prefix = "c";
                    break;

                case IfcSIPrefix.MILLI:
                    prefix = "m";
                    break;

                case IfcSIPrefix.KILO:
                    prefix = "k";
                    break;

                default:     //TODO: the other values of IfcSIPrefix
                    prefix = ifcSIPrefix.ToString();
                    break;
                }
            }

            switch (ifcSIUnitName)
            {
            case IfcSIUnitName.METRE:
                value = prefix + "m";
                break;

            case IfcSIUnitName.SQUARE_METRE:
                value = prefix + "m" + '\u00B2';     //((char)0x00B2)might need to look at this for other cultures
                break;

            case IfcSIUnitName.CUBIC_METRE:
                value = prefix + "m" + '\u00B3';    //((char)0x00B3)
                break;

            case IfcSIUnitName.GRAM:
                value = prefix + "g";
                break;

            default:    //TODO: the other values of IfcSIUnitName
                value = ifcSIUnit.ToString();
                break;
            }
            return(value);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Sets the Length Unit to be SIUnit and SIPrefix, returns false if the units are not SI
        /// </summary>
        /// <param name = "ua"></param>
        /// <param name = "siUnitName"></param>
        /// <param name = "siPrefix"></param>
        /// <returns></returns>
        public static bool SetSILengthUnits(this IfcUnitAssignment ua, IfcSIUnitName siUnitName, IfcSIPrefix?siPrefix)
        {
            IfcSIUnit si = ua.Units.OfType <IfcSIUnit>().FirstOrDefault(u => u.UnitType == IfcUnitEnum.LENGTHUNIT);

            if (si != null)
            {
                si.Prefix = siPrefix;
                si.Name   = siUnitName;
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 7
0
        public static void SetOrChangeConversionUnit(this IfcUnitAssignment ua, IfcUnitEnum unitType, ConversionBasedUnit unit)
        {
            IModel    model = ua.ModelOf;
            IfcSIUnit si    = ua.Units.OfType <IfcSIUnit>().FirstOrDefault(u => u.UnitType == unitType);

            if (si != null)
            {
                ua.Units.Remove(si);
                try
                {
                    model.Delete(si);
                } catch (Exception) {}
            }
            ua.Units.Add(GetNewConversionUnit(model, unitType, unit));
        }
Ejemplo n.º 8
0
        private static IfcSIUnit AddIfcSIUnit(
                                        Ifc4.Document document,
                                        Unit unit,
                                        IfcUnitEnum? ifcUnitEnum,
                                        IfcSIPrefix? ifcSIPrefix,
                                        IfcSIUnitName? ifcSIUnitName
                                    )
        {

            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;

            IfcSIUnit ifcSIUnit = new IfcSIUnit()
            {
                Id = document.GetNextSid(),
            };

            if (ifcUnitEnum.HasValue)
            {
                ifcSIUnit.UnitType = ifcUnitEnum.Value;
                ifcSIUnit.UnitTypeSpecified = true;
            }

            if (ifcSIPrefix.HasValue)
            {
                ifcSIUnit.Prefix = ifcSIPrefix.Value;
                ifcSIUnit.PrefixSpecified = true;
            }

            if (ifcSIUnitName.HasValue)
            {
                ifcSIUnit.Name = ifcSIUnitName.Value;
                ifcSIUnit.NameSpecified = true;
            }

            ifcUnitAssignmentUnits.Items.Add(ifcSIUnit);
            return ifcSIUnit;
        }
Ejemplo n.º 9
0
        public static IfcStore CreateandInitModel(string projectName, IfcUnitAssignment unitType)
        {
            IfcSIUnit unit = unitType.Units.FirstOrDefault(u => (u as IfcSIUnit).UnitType == IfcUnitEnum.LENGTHUNIT) as IfcSIUnit;

            if (unit.Name == IfcSIUnitName.METRE)
            {
                CADConfig.Units = linearUnitsType.Meters;
            }
            else
            {
                CADConfig.Units = linearUnitsType.Millimeters;
            }

            //first we need to set up some credentials for ownership of data in the new model
            var credentials = new XbimEditorCredentials
            {
                ApplicationDevelopersName = "Cad2Bim",
                ApplicationFullName       = "CadTo3D Application",
                ApplicationIdentifier     = "ThinkDev.exe",
                ApplicationVersion        = "1.0",
                EditorsFamilyName         = "Team",
                EditorsGivenName          = "ThinkDev",
                EditorsOrganisationName   = "ThinkDevTeam"
            };
            //now we can create an IfcStore, it is in Ifc4 format and will be held in memory rather than in a database
            //database is normally better in performance terms if the model is large >50MB of Ifc or if robust transactions are required

            var model = IfcStore.Create(credentials, IfcSchemaVersion.Ifc4, XbimStoreType.InMemoryModel);

            //Begin a transaction as all changes to a model are ACID
            using (var txn = model.BeginTransaction("Initialise Model"))
            {
                //create a project
                var project = model.Instances.New <IfcProject>();
                //set the units to SI (mm and metres)
                project.InitProject(CADConfig.Units);
                project.Name = projectName;
                //now commit the changes, else they will be rolled back at the end of the scope of the using statement
                txn.Commit();
            }
            return(model);
        }
Ejemplo n.º 10
0
        public static void SetOrChangeSIUnit(this IfcUnitAssignment ua, IfcUnitEnum unitType, IfcSIUnitName siUnitName,
                                             IfcSIPrefix?siUnitPrefix)
        {
            IModel    model = ua.ModelOf;
            IfcSIUnit si    = ua.Units.OfType <IfcSIUnit>().FirstOrDefault(u => u.UnitType == unitType);

            if (si != null)
            {
                si.Prefix = siUnitPrefix;
                si.Name   = siUnitName;
            }
            else
            {
                ua.Units.Add(model.Instances.New <IfcSIUnit>(s =>
                {
                    s.UnitType = unitType;
                    s.Name     = siUnitName;
                    s.Prefix   = siUnitPrefix;
                }));
            }
        }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Returns the full name of the unit
        /// </summary>
        /// <returns>string holding name</returns>
        public static string GetName(this IfcSIUnit ifcSIUnit)
        {
            string prefixUnit = (ifcSIUnit.Prefix.HasValue) ? ifcSIUnit.Prefix.ToString() : ""; //see IfcSIPrefix
            string value      = ifcSIUnit.Name.ToString();                                      //see IfcSIUnitName

            //Handle the "_" in _name value, should work for lengths, but might have to look at other values later
            if (!string.IsNullOrEmpty(value))
            {
                if (value.Contains("_"))
                {
                    return(value = value.Replace("_", prefixUnit));
                }
                else
                {
                    return(value = prefixUnit + value); //combine to give length name
                }
            }
            else
            {
                return(string.Format("{0}{1}", ifcSIUnit.Prefix.HasValue ? ifcSIUnit.Prefix.Value.ToString() : "", ifcSIUnit.Name.ToString()));
            }
        }
        internal static void ResolveUnits(IfcStore ifcStore, Dictionary <string, string> propertySetNamePropertyNameToUnit)
        {
            IEnumerable <IfcPropertySet> psets = ifcStore.Instances.OfType <IfcPropertySet>();

            foreach (IfcPropertySet pset in psets)
            {
                if (pset != null && pset.Name != null)
                {
                    IItemSet <IfcProperty> properties = pset.HasProperties;
                    foreach (IfcProperty property in properties)
                    {
                        if (property is IIfcPropertySingleValue && property != null && property.Name != null)
                        {
                            IIfcPropertySingleValue propertySingleValue = property as IIfcPropertySingleValue;

                            IfcUnitEnum ifcUnitEnum = resolveUnit(propertySingleValue);
                            if (!ifcUnitEnum.Equals(IfcUnitEnum.USERDEFINED))
                            {
                                var key = pset.Name + "_" + property.Name;
                                if (!propertySetNamePropertyNameToUnit.ContainsKey(key))
                                {
                                    IfcSIUnit ifcSIUnit = ifcStore.FederatedInstances
                                                          .Where <IfcSIUnit>(a => a.UnitType.ToString().Equals(ifcUnitEnum.ToString()))
                                                          .FirstOrDefault <IfcSIUnit>();

                                    if (ifcSIUnit != null && ifcSIUnit.Symbol != null)
                                    {
                                        var value = ifcSIUnit.UnitType.ToString() + "|" + ifcSIUnit.Symbol.ToString();
                                        propertySetNamePropertyNameToUnit.Add(key, value);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 14
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("");
        }
Ejemplo n.º 15
0
        /// <summary>
        ///   returns the power of the SIUnit prefix, i.e. MILLI = 0.001, if undefined returns 1.0
        /// </summary>
        /// <param name = "si"></param>
        /// <returns></returns>
        public static double Power(this IfcSIUnit si)
        {
            int exponential = 1;

            if (si.UnitType == IfcUnitEnum.AREAUNIT)
            {
                exponential = 2;
            }
            if (si.UnitType == IfcUnitEnum.VOLUMEUNIT)
            {
                exponential = 3;
            }
            double factor;

            if (si.Prefix.HasValue)
            {
                switch (si.Prefix.Value)
                {
                case IfcSIPrefix.EXA:
                    factor = 1.0e+18; break;

                case IfcSIPrefix.PETA:
                    factor = 1.0e+15; break;

                case IfcSIPrefix.TERA:
                    factor = 1.0e+12; break;

                case IfcSIPrefix.GIGA:
                    factor = 1.0e+9; break;

                case IfcSIPrefix.MEGA:
                    factor = 1.0e+6; break;

                case IfcSIPrefix.KILO:
                    factor = 1.0e+3; break;

                case IfcSIPrefix.HECTO:
                    factor = 1.0e+2; break;

                case IfcSIPrefix.DECA:
                    factor = 10; break;

                case IfcSIPrefix.DECI:
                    factor = 1.0e-1; break;

                case IfcSIPrefix.CENTI:
                    factor = 1.0e-2; break;

                case IfcSIPrefix.MILLI:
                    factor = 1.0e-3; break;

                case IfcSIPrefix.MICRO:
                    factor = 1.0e-6; break;

                case IfcSIPrefix.NANO:
                    factor = 1.0e-9; break;

                case IfcSIPrefix.PICO:
                    factor = 1.0e-12; break;

                case IfcSIPrefix.FEMTO:
                    factor = 1.0e-15; break;

                case IfcSIPrefix.ATTO:
                    factor = 1.0e-18; break;

                default:
                    factor = 1.0; break;
                }
                return(Math.Pow(factor, exponential));
            }
            else
            {
                return(1.0);
            }
        }
Ejemplo n.º 16
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);
        }
Ejemplo n.º 17
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);
        }
Ejemplo n.º 18
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");
        }
Ejemplo n.º 19
0
 internal void initData()
 {
     initGeom();
     mSILength = new IfcSIUnit(mDatabase, IfcUnitEnum.LENGTHUNIT, IfcSIPrefix.NONE, IfcSIUnitName.METRE);
     mSIArea = new IfcSIUnit(mDatabase, IfcUnitEnum.AREAUNIT, IfcSIPrefix.NONE, IfcSIUnitName.SQUARE_METRE);
     mSIVolume = new IfcSIUnit(mDatabase, IfcUnitEnum.VOLUMEUNIT, IfcSIPrefix.NONE, IfcSIUnitName.CUBIC_METRE);
 }