コード例 #1
0
        public string Format(string fmt, object arg, IFormatProvider formatProvider)
        {
            // Convert argument to a string

            if (!String.IsNullOrEmpty(fmt) && fmt.ToUpper() == "R" && arg.GetType() == typeof(double))
            {
                double dArg   = (double)arg;
                string result = dArg.ToString("R", CultureInfo.CreateSpecificCulture("en-US"));

                // if compiler flag, only then do the following 3 lines
                string rDoubleStr = dArg.ToString("R", CultureInfo.CreateSpecificCulture("en-US"));
                double fixedDbl   = double.Parse(rDoubleStr, CultureInfo.CreateSpecificCulture("en-US"));
                result = fixedDbl.ToString("R", CultureInfo.CreateSpecificCulture("en-US"));

                //decimal decArg = new Decimal(dArg);
                // string result = decArg.ToString().ToUpper();
                // string result = string.Format("{0:e22}", arg);
                //string result = dArg.ToString("R", CultureInfo.CreateSpecificCulture("en-US"));
                if (!result.Contains("."))
                {
                    if (result.Contains("E"))
                    {
                        result = result.Replace("E", ".E");
                    }
                    else
                    {
                        result += ".";
                    }
                }

                return(result);
            }
            else if (!String.IsNullOrEmpty(fmt) && fmt.ToUpper() == "T") //TimeStamp
            {
                string   result = arg.ToString().ToUpper();
                DateTime?dt     = arg as DateTime?;
                if (dt.HasValue == false)
                {
                    throw new ArgumentException("Only valid DateTime objects can be converted to Part21 Timestamp");
                }
                return(IfcTimeStamp.ToTimeStamp(dt.Value).ToPart21);
            }
            else if (!String.IsNullOrEmpty(fmt) && fmt.ToUpper() == "G") //Guid
            {
                string result = arg.ToString().ToUpper();
                Guid   guid   = (Guid)arg;
                return(string.Format(@"'{0}'", IfcGloballyUniqueId.AsPart21(guid)));
            }
            // Return string representation of argument for any other formatting code
            else
            {
                return(string.Format(@"'{0}'", IfcText.Escape(arg.ToString())));
            }
        }
コード例 #2
0
        public static IfcOwnerHistory NewIfc2x3OwnerHistoryEntry(this IfcStore s, string version, IfcChangeActionEnum change = IfcChangeActionEnum.ADDED)
        {
            var newEntry = s.Instances.New <IfcOwnerHistory>();

            newEntry.ChangeAction = change;
            var dateTime = IfcTimeStamp.ToTimeStamp(DateTime.Now);

            newEntry.CreationDate      = dateTime;
            newEntry.LastModifiedDate  = dateTime;
            newEntry.OwningUser        = s.DefaultOwningUser as IfcPersonAndOrganization;
            newEntry.OwningApplication = s.DefaultOwningApplication as IfcApplication;
            return(newEntry);
        }
コード例 #3
0
        /// <summary>
        /// Converts an attribute in to an Ifc Property, still needs support for units adding
        /// </summary>
        /// <param name="attributeType"></param>
        /// <returns></returns>
        internal IfcSimpleProperty ConvertAttributeTypeToIfcSimpleProperty(AttributeType attributeType)
        {
            var attributeValueType = attributeType.AttributeValue;

            IfcSimpleProperty theProperty;

            var simplePropertyType = attributeValueType.SimplePropertyType();

            switch (simplePropertyType)
            {
            case XbimSimplePropertyType.SimpleDecimal:
            case XbimSimplePropertyType.SimpleInteger:
            case XbimSimplePropertyType.SimpleBoolean:
            case XbimSimplePropertyType.SimpleMonetary:
            case XbimSimplePropertyType.SimpleString:
            case XbimSimplePropertyType.SimpleDateTime:
            case XbimSimplePropertyType.Null:
                theProperty = TargetRepository.Instances.New <IfcPropertySingleValue>();
                break;

            case XbimSimplePropertyType.BoundedDecimal:
            case XbimSimplePropertyType.BoundedInteger:
                theProperty = TargetRepository.Instances.New <IfcPropertyBoundedValue>();
                break;

            case XbimSimplePropertyType.EnumerationString:
                theProperty = TargetRepository.Instances.New <IfcPropertyEnumeratedValue>();
                break;

            default:
                throw new ArgumentOutOfRangeException("attributeType", "Invalid attribute value type");
            }

            theProperty.Name        = attributeType.AttributeName;
            theProperty.Description = attributeType.AttributeDescription;
            if (attributeValueType != null)
            {
                switch (simplePropertyType)
                {
                case XbimSimplePropertyType.SimpleDecimal:
                    var    attributeDecimalValueType = attributeValueType.Item as AttributeDecimalValueType;
                    double?decimalValue;
                    if (attributeDecimalValueType != null && attributeDecimalValueType.DecimalValueSpecified)
                    {
                        decimalValue = attributeDecimalValueType.DecimalValue;
                    }
                    else
                    {
                        decimalValue = null;
                    }
                    var simpleProperty = (IfcPropertySingleValue)theProperty;
                    if (decimalValue.HasValue)
                    {
                        simpleProperty.NominalValue = new IfcReal(decimalValue.Value);
                    }
                    //if (attributeDecimalValueType != null)
                    //{
                    //    var unitConverter = new IfcUnitConverter(attributeDecimalValueType.UnitName);
                    //    if (!unitConverter.IsUndefined)
                    //        simpleProperty.Unit = unitConverter.IfcUnit(TargetRepository);
                    //}
                    break;

                case XbimSimplePropertyType.BoundedDecimal:
                    var    attributeBoundedDecimalValueType = attributeValueType.Item as AttributeDecimalValueType;
                    double?maxDecimalValue;
                    double?minDecimalValue;
                    if (attributeBoundedDecimalValueType != null &&
                        attributeBoundedDecimalValueType.MaxValueDecimalSpecified)
                    {
                        maxDecimalValue = attributeBoundedDecimalValueType.MaxValueDecimal;
                    }
                    else
                    {
                        maxDecimalValue = null;
                    }
                    if (attributeBoundedDecimalValueType != null &&
                        attributeBoundedDecimalValueType.MinValueDecimalSpecified)
                    {
                        minDecimalValue = attributeBoundedDecimalValueType.MinValueDecimal;
                    }
                    else
                    {
                        minDecimalValue = null;
                    }
                    var boundedProperty = (IfcPropertyBoundedValue)theProperty;
                    if (maxDecimalValue.HasValue)
                    {
                        boundedProperty.UpperBoundValue = new IfcReal(maxDecimalValue.Value);
                    }
                    if (minDecimalValue.HasValue)
                    {
                        boundedProperty.LowerBoundValue = new IfcReal(minDecimalValue.Value);
                    }
                    break;

                case XbimSimplePropertyType.SimpleInteger:
                    var attributeSimpleIntegerValueType = attributeValueType.Item as AttributeIntegerValueType;
                    if (attributeSimpleIntegerValueType != null &&
                        attributeSimpleIntegerValueType.IntegerValue.HasValue)
                    {
                        var simpleIntProperty = (IfcPropertySingleValue)theProperty;
                        simpleIntProperty.NominalValue =
                            new IfcInteger(attributeSimpleIntegerValueType.IntegerValue.Value);
                    }
                    break;

                case XbimSimplePropertyType.BoundedInteger:
                    var attributeBoundedIntegerValueType = attributeValueType.Item as AttributeIntegerValueType;
                    if (attributeBoundedIntegerValueType != null)
                    {
                        var boundedIntegerProperty = (IfcPropertyBoundedValue)theProperty;
                        if (attributeBoundedIntegerValueType.MaxValueInteger.HasValue)
                        {
                            boundedIntegerProperty.UpperBoundValue =
                                new IfcInteger(attributeBoundedIntegerValueType.MaxValueInteger.Value);
                        }
                        if (attributeBoundedIntegerValueType.MinValueInteger.HasValue)
                        {
                            boundedIntegerProperty.LowerBoundValue =
                                new IfcInteger(attributeBoundedIntegerValueType.MinValueInteger.Value);
                        }
                    }
                    break;

                case XbimSimplePropertyType.SimpleBoolean:
                    var attributeBooleanValueType = attributeValueType.Item as BooleanValueType;
                    if (attributeBooleanValueType != null && attributeBooleanValueType.BooleanValueSpecified)
                    {
                        var simpleBooleanProperty = (IfcPropertySingleValue)theProperty;
                        simpleBooleanProperty.NominalValue = new IfcBoolean(attributeBooleanValueType.BooleanValue);
                    }
                    break;

                case XbimSimplePropertyType.SimpleMonetary:
                    var attributeMonetaryValueType = attributeValueType.Item as AttributeMonetaryValueType;
                    if (attributeMonetaryValueType != null)
                    {
                        var simpleMonetaryProperty = (IfcPropertySingleValue)theProperty;
                        var monetaryValue          = (double)attributeMonetaryValueType.MonetaryValue;
                        simpleMonetaryProperty.NominalValue = new IfcReal(monetaryValue);
                        IfcCurrencyEnum currencyEnum;
                        if (Enum.TryParse(attributeMonetaryValueType.MonetaryUnit.ToString(), true, out currencyEnum))
                        {
                            simpleMonetaryProperty.Unit = new IfcMonetaryUnit {
                                Currency = currencyEnum
                            }
                        }
                        ;
                    }
                    break;

                case XbimSimplePropertyType.EnumerationString:
                    var attributeEnumStringValueType = attributeValueType.Item as AttributeStringValueType;
                    if (attributeEnumStringValueType != null)
                    {
                        var simpleEnumStringProperty = (IfcPropertyEnumeratedValue)theProperty;
                        simpleEnumStringProperty.EnumerationValues.Add(
                            new IfcLabel(attributeEnumStringValueType.StringValue));
                        if (attributeEnumStringValueType.AllowedValues != null &&
                            attributeEnumStringValueType.AllowedValues.Any())
                        {
                            simpleEnumStringProperty.EnumerationReference =
                                TargetRepository.Instances.New <IfcPropertyEnumeration>();
                            foreach (var allowedValue in attributeEnumStringValueType.AllowedValues)
                            {
                                simpleEnumStringProperty.EnumerationReference.Name = attributeType.AttributeName;
                                simpleEnumStringProperty.EnumerationReference.EnumerationValues.Add(
                                    new IfcLabel(allowedValue));
                            }
                        }
                    }
                    break;

                case XbimSimplePropertyType.SimpleString:
                case XbimSimplePropertyType.Null:
                    var attributeStringValueType = attributeValueType.Item as AttributeStringValueType;
                    if (attributeStringValueType != null)
                    {
                        var simpleStringProperty = (IfcPropertySingleValue)theProperty;
                        simpleStringProperty.NominalValue = new IfcText(attributeStringValueType.StringValue);
                    }
                    break;

                case XbimSimplePropertyType.SimpleDateTime:
                    if (attributeValueType.Item is DateTime)
                    {
                        var simpleDateTimeProperty     = (IfcPropertySingleValue)theProperty;
                        var attributeDateTimeValueType = (DateTime)attributeValueType.Item;
                        simpleDateTimeProperty.NominalValue = IfcTimeStamp.ToTimeStamp(attributeDateTimeValueType);
                    }
                    break;

                default:
                    throw new ArgumentOutOfRangeException("attributeType", "Invalid attribute value type");
                }
            }
            return(theProperty);
        }
コード例 #4
0
 /// <summary>
 ///   Creates an Ifc schema compliant OwnerHistory, Creation Date default to Now, changeAction to ADDED
 /// </summary>
 public IfcOwnerHistory()
 {
     _creationDate = IfcTimeStamp.ToTimeStamp(DateTime.UtcNow);
 }
コード例 #5
0
        private static void WriteValueType(Type pInfoType, object pVal, BinaryWriter entityWriter)
        {
            if (pInfoType == typeof(Double))
            {
                entityWriter.Write(Convert.ToByte(P21ParseAction.SetFloatValue));
                entityWriter.Write((double)pVal);
            }
            else if (pInfoType == typeof(String)) //convert  string
            {
                if (pVal == null)
                {
                    entityWriter.Write(Convert.ToByte(P21ParseAction.SetNonDefinedValue));
                }
                else
                {
                    entityWriter.Write(Convert.ToByte(P21ParseAction.SetStringValue));
                    entityWriter.Write((string)pVal);
                }
            }
            else if (pInfoType == typeof(Int16))
            {
                entityWriter.Write(Convert.ToByte(P21ParseAction.SetIntegerValue));
                entityWriter.Write((long)(Int16)pVal);
            }
            else if (pInfoType == typeof(Int32))
            {
                entityWriter.Write(Convert.ToByte(P21ParseAction.SetIntegerValue));
                entityWriter.Write((long)(Int32)pVal);
            }
            else if (pInfoType == typeof(Int64))
            {
                entityWriter.Write(Convert.ToByte(P21ParseAction.SetIntegerValue));
                entityWriter.Write((long)pVal);
            }
            else if (pInfoType.IsEnum) //convert enum
            {
                entityWriter.Write(Convert.ToByte(P21ParseAction.SetEnumValue));
                entityWriter.Write(pVal.ToString().ToUpper());
            }
            else if (pInfoType == typeof(Boolean))
            {
                if (pVal == null) //we have a logical
                {
                    entityWriter.Write(Convert.ToByte(P21ParseAction.SetNonDefinedValue));
                }
                else
                {
                    entityWriter.Write(Convert.ToByte(P21ParseAction.SetBooleanValue));
                    entityWriter.Write((bool)pVal);
                }
            }

            else if (pInfoType == typeof(DateTime)) //convert  TimeStamp
            {
                IfcTimeStamp ts = IfcTimeStamp.ToTimeStamp((DateTime)pVal);
                entityWriter.Write(Convert.ToByte(P21ParseAction.SetIntegerValue));
                entityWriter.Write((long)ts);
            }
            else if (pInfoType == typeof(Guid)) //convert  Guid string
            {
                if (pVal == null)
                {
                    entityWriter.Write(Convert.ToByte(P21ParseAction.SetNonDefinedValue));
                }
                else
                {
                    entityWriter.Write(Convert.ToByte(P21ParseAction.SetStringValue));
                    entityWriter.Write((string)pVal);
                }
            }
            else if (pInfoType == typeof(bool?)) //convert  logical
            {
                bool?b = (bool?)pVal;
                if (!b.HasValue)
                {
                    entityWriter.Write(Convert.ToByte(P21ParseAction.SetNonDefinedValue));
                }
                else
                {
                    entityWriter.Write(Convert.ToByte(P21ParseAction.SetBooleanValue));
                    entityWriter.Write(b.Value);
                }
            }
            else
            {
                throw new ArgumentException(string.Format("Invalid Value Type {0}", pInfoType.Name), "pInfoType");
            }
        }