/// <summary> /// Gets the object type of a handle. /// </summary> /// <param name="handle">The handle.</param> /// <returns>The object type.</returns> public static string GetObjectType(IFCAnyHandle handle) { if (handle == null) { throw new ArgumentNullException("handle"); } if (!handle.HasValue) { throw new ArgumentException("Invalid handle."); } if (!IsSubTypeOf(handle, IFCEntityType.IfcObject)) { throw new ArgumentException("Not an IfcObject handle."); } IFCData ifcData = handle.GetAttribute("ObjectType"); if (ifcData.PrimitiveType == IFCDataPrimitiveType.String) { return(ifcData.AsString()); } throw new InvalidOperationException("Failed to get object type."); }
/// <summary> /// Gets Description of an IfcProductDefinitionShape handle. /// </summary> /// <param name="representation">The IfcProductDefinitionShape.</param> /// <returns>The Description string.</returns> public static string GetProductDefinitionShapeDescription(IFCAnyHandle productDefinitionShape) { if (productDefinitionShape == null) { throw new ArgumentNullException("productDefinitionShape"); } if (!productDefinitionShape.HasValue) { throw new ArgumentException("Invalid handle."); } if (!IsSubTypeOf(productDefinitionShape, IFCEntityType.IfcProductDefinitionShape)) { throw new ArgumentException("The operation is not valid for this handle."); } IFCData ifcData = productDefinitionShape.GetAttribute("Description"); if (ifcData.PrimitiveType == IFCDataPrimitiveType.String) { return(ifcData.AsString()); } return(null); }
/// <summary> /// Gets ContextOfItems of a representation handle. /// </summary> /// <param name="representation">The representation.</param> /// <returns>The ContextOfItems handle.</returns> public static IFCAnyHandle GetContextOfItems(IFCAnyHandle representation) { if (representation == null) { throw new ArgumentNullException("representation"); } if (!representation.HasValue) { throw new ArgumentException("Invalid handle."); } if (!IsSubTypeOf(representation, IFCEntityType.IfcRepresentation)) { throw new ArgumentException("The operation is not valid for this handle."); } IFCData ifcData = representation.GetAttribute("ContextOfItems"); if (ifcData.PrimitiveType == IFCDataPrimitiveType.Instance) { return(ifcData.AsInstance()); } return(null); }
private string UsablePropertyName(IFCAnyHandle propHnd, IDictionary <string, IFCAnyHandle> propertiesByName) { if (IFCAnyHandleUtil.IsNullOrHasNoValue(propHnd)) { return(null); } string currPropertyName = IFCAnyHandleUtil.GetStringAttribute(propHnd, "Name"); if (string.IsNullOrWhiteSpace(currPropertyName)) { return(null); // This shouldn't be posssible. } // Don't override if the new value is empty. if (propertiesByName.ContainsKey(currPropertyName)) { try { // Only IfcSimplePropertyValue has the NominalValue attribute; any other type of property will throw. IFCData currPropertyValue = propHnd.GetAttribute("NominalValue"); if (currPropertyValue.PrimitiveType == IFCDataPrimitiveType.String && string.IsNullOrWhiteSpace(currPropertyValue.AsString())) { return(null); } } catch { // Not an IfcSimplePropertyValue - no need to verify. } } return(currPropertyName); }
/// <summary> /// Gets representation of a product handle. /// </summary> /// <param name="productHandle">The product handle.</param> /// <returns>The representation handle.</returns> public static IFCAnyHandle GetRepresentation(IFCAnyHandle productHandle) { if (productHandle == null) { throw new ArgumentNullException("productHandle"); } if (!productHandle.HasValue) { throw new ArgumentException("Invalid handle."); } if (!IsSubTypeOf(productHandle, IFCEntityType.IfcProduct)) { throw new ArgumentException("The operation is not valid for this handle."); } IFCData ifcData = productHandle.GetAttribute("Representation"); if (ifcData.PrimitiveType == IFCDataPrimitiveType.Instance) { return(ifcData.AsInstance()); } return(null); }
/// <summary> /// Processes an IFC bounded value property. /// </summary> /// <param name="ifcPropertyBoundedValue">The IfcPropertyBoundedValue object.</param> /// <returns>The IFCPropertyBoundedValue object.</returns> override protected void Process(IFCAnyHandle ifcPropertyBoundedValue) { base.Process(ifcPropertyBoundedValue); IFCData lowerBoundValue = ifcPropertyBoundedValue.GetAttribute("LowerBoundValue"); IFCData upperBoundValue = ifcPropertyBoundedValue.GetAttribute("UpperBoundValue"); IFCData setPointValue = (IFCImportFile.TheFile.SchemaVersion > IFCSchemaVersion.IFC2x3) ? ifcPropertyBoundedValue.GetAttribute("SetPointValue") : null; if (lowerBoundValue != null) { m_LowerBoundPropertyIndex = IFCPropertyValues.Count; IFCPropertyValues.Add(new IFCPropertyValue(this, lowerBoundValue)); } if (upperBoundValue != null) { m_UpperBoundPropertyIndex = IFCPropertyValues.Count; IFCPropertyValues.Add(new IFCPropertyValue(this, upperBoundValue)); } if (setPointValue != null) { m_SetPointValueIndex = IFCPropertyValues.Count; IFCPropertyValues.Add(new IFCPropertyValue(this, setPointValue)); } ProcessIFCSimplePropertyUnit(this, ifcPropertyBoundedValue); }
/// <summary> /// Gets aggregate attribute values from a handle. /// </summary> /// <typeparam name="T">The return type.</typeparam> /// <param name="handle">The handle.</param> /// <param name="name">The attribute name.</param> /// <returns>The collection of attribute values.</returns> public static T GetAggregateInstanceAttribute <T>(IFCAnyHandle handle, string name) where T : ICollection <IFCAnyHandle>, new() { if (handle == null) { throw new ArgumentNullException("handle"); } if (!handle.HasValue) { throw new ArgumentException("Invalid handle."); } IFCData ifcData = handle.GetAttribute(name); T aggregateAttribute = default(T); if (ifcData.PrimitiveType == IFCDataPrimitiveType.Aggregate) { IFCAggregate aggregate = ifcData.AsAggregate(); if (aggregate != null) { aggregateAttribute = new T(); foreach (IFCData val in aggregate) { if (val.PrimitiveType == IFCDataPrimitiveType.Instance) { aggregateAttribute.Add(val.AsInstance()); } } } } return(aggregateAttribute); }
/// <summary> /// Gets Identifier of a representation handle. /// </summary> /// <param name="representation">The representation item.</param> /// <returns>The RepresentationIdentifier string.</returns> public static string GetRepresentationIdentifier(IFCAnyHandle representation) { if (representation == null) { throw new ArgumentNullException("representation"); } if (!representation.HasValue) { throw new ArgumentException("Invalid handle."); } if (!IsSubTypeOf(representation, IFCEntityType.IfcRepresentation)) { throw new ArgumentException("The operation is not valid for this handle."); } IFCData ifcData = representation.GetAttribute("RepresentationIdentifier"); if (ifcData.PrimitiveType == IFCDataPrimitiveType.String) { return(ifcData.AsString()); } return(null); }
/// <summary> /// Creates an IFCData object as IfcText. /// </summary> /// <param name="value">The string value.</param> /// <returns>The IFCData object.</returns> public static IFCData CreateAsText(string value) { if (value == null) { return(null); } return(IFCData.CreateStringOfType(value, "IfcText")); }
/// <summary> /// Creates an IFCData object as IfcIdentifier. /// </summary> /// <param name="value">The string value.</param> /// <returns>The IFCData object.</returns> public static IFCData CreateAsIdentifier(string value) { if (value == null) { return(null); } return(IFCData.CreateStringOfType(value.Length > 255 ? value.Remove(255) : value, "IfcIdentifier")); }
private double?GetTrimParameter(IFCData trim, IFCCurve basisCurve, IFCTrimmingPreference trimPreference, bool secondAttempt) { bool preferParam = !(trimPreference == IFCTrimmingPreference.Cartesian); if (secondAttempt) { preferParam = !preferParam; } double vertexEps = MathUtil.VertexEps; IFCAggregate trimAggregate = trim.AsAggregate(); foreach (IFCData trimParam in trimAggregate) { if (!preferParam && (trimParam.PrimitiveType == IFCDataPrimitiveType.Instance)) { IFCAnyHandle trimParamInstance = trimParam.AsInstance(); XYZ trimParamPt = IFCPoint.ProcessScaledLengthIFCCartesianPoint(trimParamInstance); if (trimParamPt == null) { IFCImportFile.TheLog.LogWarning(basisCurve.Id, "Invalid trim point for basis curve.", false); continue; } try { IntersectionResult result = basisCurve.Curve.Project(trimParamPt); if (result.Distance < vertexEps) { return(result.Parameter); } IFCImportFile.TheLog.LogWarning(basisCurve.Id, "Cartesian value for trim point not on the basis curve.", false); } catch { IFCImportFile.TheLog.LogWarning(basisCurve.Id, "Cartesian value for trim point not on the basis curve.", false); } } else if (preferParam && (trimParam.PrimitiveType == IFCDataPrimitiveType.Double)) { double trimParamDouble = trimParam.AsDouble(); if (basisCurve.Curve.IsCyclic) { trimParamDouble = IFCUnitUtil.ScaleAngle(trimParamDouble); } return(trimParamDouble); } } // Try again with opposite preference. if (!secondAttempt) { return(GetTrimParameter(trim, basisCurve, trimPreference, true)); } return(null); }
/// <summary> /// Sets logical attribute for the handle. /// </summary> /// <remarks> /// If value is null or empty, the attribute will be unset. /// </remarks> /// <param name="handle">The handle.</param> /// <param name="name">The attribute name.</param> /// <param name="value">The logical value.</param> /// <exception cref="ArgumentException">If the name is null or empty.</exception> public static void SetAttribute(IFCAnyHandle handle, string name, IFCLogical value) { if (String.IsNullOrEmpty(name)) { throw new ArgumentException("The name is empty.", "name"); } handle.SetAttribute(name, IFCData.CreateLogical(value)); }
/// <summary> /// Creates an IFCData object as IfcLogical. /// </summary> /// <param name="value">The logical value.</param> /// <returns>The IFCData object.</returns> public static IFCData CreateAsLogical(IFCLogical value) { IFCData ifcData = IFCData.CreateLogical(value); IList <string> types = new List <string>(); types.Add("IfcLogical"); ifcData.SetTypeList(types); return(ifcData); }
/// <summary> /// Processes an IFC physical simple quantity. /// </summary> /// <param name="ifcPhysicalQuantity">The IfcPhysicalSimpleQuantity object.</param> /// <returns>The IFCPhysicalSimpleQuantity object.</returns> override protected void Process(IFCAnyHandle ifcPhysicalSimpleQuantity) { base.Process(ifcPhysicalSimpleQuantity); IFCAnyHandle unit = IFCImportHandleUtil.GetOptionalInstanceAttribute(ifcPhysicalSimpleQuantity, "Unit"); if (!IFCAnyHandleUtil.IsNullOrHasNoValue(unit)) { IFCUnit = IFCUnit.ProcessIFCUnit(unit); } // Process subtypes of IfcPhysicalSimpleQuantity here. string attributeName = ifcPhysicalSimpleQuantity.TypeName.Substring(11) + "Value"; Value = ifcPhysicalSimpleQuantity.GetAttribute(attributeName); BaseUnitType = IFCDataUtil.GetUnitTypeFromData(Value, UnitType.UT_Undefined); if (BaseUnitType == UnitType.UT_Undefined) { // Determine it from the attributeName. if (string.Compare(attributeName, "LengthValue", true) == 0) { BaseUnitType = UnitType.UT_Length; } else if (string.Compare(attributeName, "AreaValue", true) == 0) { BaseUnitType = UnitType.UT_Area; } else if (string.Compare(attributeName, "VolumeValue", true) == 0) { BaseUnitType = UnitType.UT_Volume; } else if (string.Compare(attributeName, "CountValue", true) == 0) { BaseUnitType = UnitType.UT_Number; } else if (string.Compare(attributeName, "WeightValue", true) == 0) { BaseUnitType = UnitType.UT_Mass; } else if (string.Compare(attributeName, "TimeValue", true) == 0) { BaseUnitType = UnitType.UT_Number; // No time unit type in Revit. } else { Importer.TheLog.LogWarning(Id, "Can't determine unit type for IfcPhysicalSimpleQuantity of type: " + attributeName, true); BaseUnitType = UnitType.UT_Number; } } if (IFCUnit == null) { IFCUnit = IFCImportFile.TheFile.IFCUnits.GetIFCProjectUnit(BaseUnitType); } }
private int?GetValidIndex(IFCData segmentInfoIndex, int maxValue) { // Index starts at 1. int currentIndex = segmentInfoIndex.AsInteger() - 1; if (currentIndex < 0 || currentIndex >= maxValue) { // TODO: warn. return(null); } return(currentIndex); }
/// <summary> /// Sets IFCValue attribute for the handle. /// </summary> /// <remarks> /// If value is null, the attribute will be unset. /// </remarks> /// <param name="handle">The handle.</param> /// <param name="name">The attribute name.</param> /// <param name="value">The value.</param> /// <exception cref="ArgumentException">If the name is null or empty.</exception> public static void SetAttribute(IFCAnyHandle handle, string name, IFCData value) { if (String.IsNullOrEmpty(name)) { throw new ArgumentException("The name is empty.", "name"); } if (value != null) { handle.SetAttribute(name, value); } }
/// <summary> /// Creates an IFCData object as IfcCountMeasure. /// </summary> /// <param name="value">The integer value.</param> /// <returns>The IFCData object.</returns> public static IFCData CreateAsCountMeasure(double value) { int valueAsInt = Convert.ToInt32(value); if (MathUtil.IsAlmostZero(value - valueAsInt)) { return(IFCData.CreateIntegerOfType(valueAsInt, "IfcCountMeasure")); } else { return(CreateAsMeasure(value, "IfcCountMeasure")); } }
/// <summary> /// Creates an IFCData object as IfcIdentifier. /// </summary> /// <param name="value">The string value.</param> /// <returns>The IFCData object.</returns> public static IFCData CreateAsIdentifier(string value) { if (value == null) { return(null); } if (value.Length > IFCLimits.MAX_IFCIDENTIFIER_STR_LEN) { OnIFCStringTooLongWarn(value, IFCLimits.MAX_IFCIDENTIFIER_STR_LEN); value = value.Remove(IFCLimits.MAX_IFCIDENTIFIER_STR_LEN); } return(IFCData.CreateStringOfType(value, "IfcIdentifier")); }
/// <summary> /// Creates an IFCData object as IfcLabel. /// </summary> /// <param name="value">The string value.</param> /// <returns>The IFCData object.</returns> public static IFCData CreateAsLabel(string value) { if (value == null) { return(null); } if (value.Length > IFCLimits.MAX_IFCLABEL_STR_LEN) { OnIFCStringTooLongWarn(value, IFCLimits.MAX_IFCLABEL_STR_LEN); value = value.Remove(IFCLimits.MAX_IFCLABEL_STR_LEN); } return(IFCData.CreateStringOfType(value, "IfcLabel")); }
/// <summary> /// Check that an IFCData is properly formatted to potentially be an IfcSegmentIndexSelect. /// </summary> /// <param name="segment"></param> /// <returns>The type of IfcSegmentIndexSelect, or null if invalid.</returns> /// <remarks>The calling function is responsible for logging errors.</remarks> private string ValidateSegment(IFCData segment) { if (segment.PrimitiveType != IFCDataPrimitiveType.Aggregate) { return(null); } if (!segment.HasSimpleType()) { return(null); } return(segment.GetSimpleType()); }
private double?GetRawTrimParameter(IFCData trim) { IFCAggregate trimAggregate = trim.AsAggregate(); foreach (IFCData trimParam in trimAggregate) { if (trimParam.PrimitiveType == IFCDataPrimitiveType.Double) { return(trimParam.AsDouble()); } } return(null); }
/// <summary> /// Creates an IFCData object as IfcLabel. /// </summary> /// <param name="value">The string value.</param> /// <returns>The IFCData object.</returns> public static IFCData CreateAsLabel(string value) { if (value == null) { return(null); } value = new string(value.Where(c => !char.IsControl(c)).ToArray()); if (value.Length > IFCLimits.MAX_IFCLABEL_STR_LEN) { OnIFCStringTooLongWarn(value, IFCLimits.MAX_IFCLABEL_STR_LEN); value = value.Remove(IFCLimits.MAX_IFCLABEL_STR_LEN); } return(IFCData.CreateStringOfType(value, "IfcLabel")); }
/// <summary> /// Creates an IFCData object as IfcText. /// </summary> /// <param name="value">The string value.</param> /// <returns>The IFCData object.</returns> public static IFCData CreateAsText(string value) { if (value == null) { return(null); } int maxStrLen = IFCLimits.CalculateMaxAllowedSize(value); if (value.Length > maxStrLen) { OnIFCStringTooLongWarn(value, maxStrLen); value = value.Remove(maxStrLen); } return(IFCData.CreateStringOfType(value, "IfcText")); }
/// <summary> /// Creates an IFCData object as IfcText. /// </summary> /// <param name="value">The string value.</param> /// <returns>The IFCData object.</returns> public static IFCData CreateAsText(string value) { if (value == null) { return(null); } value = new string(value.Where(c => !char.IsControl(c)).ToArray()); int maxStrLen = IFCLimits.CalculateMaxAllowedSize(value); if (value.Length > maxStrLen) { OnIFCStringTooLongWarn(value, maxStrLen); value = value.Remove(maxStrLen); } return(IFCData.CreateStringOfType(value, "IfcText")); }
private void GetTrimParameters(int id, IFCData trim1, IFCData trim2, Curve baseCurve, IFCTrimmingPreference trimPreference, out double param1, out double param2) { double?condParam1 = GetTrimParameter(id, trim1, baseCurve, trimPreference, false); if (!condParam1.HasValue) { throw new InvalidOperationException("#" + id + ": Couldn't apply first trimming parameter of IfcTrimmedCurve."); } param1 = condParam1.Value; double?condParam2 = GetTrimParameter(id, trim2, baseCurve, trimPreference, false); if (!condParam2.HasValue) { throw new InvalidOperationException("#" + id + ": Couldn't apply second trimming parameter of IfcTrimmedCurve."); } param2 = condParam2.Value; if (MathUtil.IsAlmostEqual(param1, param2)) { // If we had a cartesian parameter as the trim preference, check if the parameter values are better. if (trimPreference == IFCTrimmingPreference.Cartesian) { condParam1 = GetTrimParameter(id, trim1, baseCurve, IFCTrimmingPreference.Parameter, true); if (!condParam1.HasValue) { throw new InvalidOperationException("#" + id + ": Couldn't apply first trimming parameter of IfcTrimmedCurve."); } param1 = condParam1.Value; condParam2 = GetTrimParameter(id, trim2, baseCurve, IFCTrimmingPreference.Parameter, true); if (!condParam2.HasValue) { throw new InvalidOperationException("#" + id + ": Couldn't apply second trimming parameter of IfcTrimmedCurve."); } param2 = condParam2.Value; } else { throw new InvalidOperationException("#" + id + ": Ignoring 0 length curve."); } } }
public static IFCAnyHandle GetOrCreateMaterialStyle(Document document, ExporterIFC exporterIFC, ElementId materialId) { IFCAnyHandle styleHnd = ExporterCacheManager.MaterialIdToStyleHandleCache.Find(materialId); if (styleHnd == null) { Material material = document.GetElement(materialId) as Material; if (material == null) { return(null); } string matName = material.Name; Color color = material.Color; double blueVal = color.Blue / 255.0; double greenVal = color.Green / 255.0; double redVal = color.Red / 255.0; IFCFile file = exporterIFC.GetFile(); IFCAnyHandle colorHnd = IFCInstanceExporter.CreateColourRgb(file, null, redVal, greenVal, blueVal); double transparency = ((double)material.Transparency) / 100.0; IFCData smoothness = IFCDataUtil.CreateAsNormalisedRatioMeasure(((double)material.Smoothness) / 100.0); IFCData specularExp = IFCDataUtil.CreateAsSpecularExponent(material.Shininess); IFCReflectanceMethod method = IFCReflectanceMethod.NotDefined; IFCAnyHandle renderingHnd = IFCInstanceExporter.CreateSurfaceStyleRendering(file, colorHnd, transparency, null, null, null, null, smoothness, specularExp, method); ICollection <IFCAnyHandle> surfStyles = new HashSet <IFCAnyHandle>(); surfStyles.Add(renderingHnd); IFCSurfaceSide surfSide = IFCSurfaceSide.Both; styleHnd = IFCInstanceExporter.CreateSurfaceStyle(file, matName, surfSide, surfStyles); ExporterCacheManager.MaterialIdToStyleHandleCache.Register(materialId, styleHnd); } return(styleHnd); }
/// <summary> /// Gets the unit type from an IFC data. /// </summary> /// <param name="data">The IFC data.</param> /// <param name="defaultType">The default value, if no type is found.</param> /// <param name="propertyType">The string value of the simple type, returned for logging purposes.</param> /// <returns>The unit type.</returns> public static UnitType GetUnitTypeFromData(IFCData data, UnitType defaultType, out string propertyType) { UnitType unitType = UnitType.UT_Undefined; if (data.HasSimpleType()) { propertyType = data.GetSimpleType(); if (!MeasureCache.TryGetValue(propertyType, out unitType)) { unitType = defaultType; } } else { propertyType = ""; unitType = defaultType; } return(unitType); }
/// <summary> /// Gets the unit type from an IFC data. /// </summary> /// <param name="data">The IFC data.</param> /// <param name="defaultSpec">The default spec, if no spec is found.</param> /// <param name="propertyType">The string value of the simple type, returned for logging purposes.</param> /// <returns>The unit type.</returns> public static ForgeTypeId GetUnitTypeFromData(IFCData data, ForgeTypeId defaultSpec, out string propertyType) { ForgeTypeId specTypeId = new ForgeTypeId(); if (data.HasSimpleType()) { propertyType = data.GetSimpleType(); if (!MeasureCache.TryGetValue(propertyType, out specTypeId)) { specTypeId = defaultSpec; } } else { propertyType = ""; specTypeId = defaultSpec; } return(specTypeId); }
/// <summary> /// Get attribute of type IList of IList of Entity /// </summary> /// <param name="handle">The handle</param> /// <param name="name">attribute name</param> /// <returns>IList of IList of Entity</returns> public static IList <IList <IFCAnyHandle> > GetListOfListOfInstanceAttribute(IFCAnyHandle handle, string name) { if (handle == null) { throw new ArgumentNullException("handle"); } if (!handle.HasValue) { throw new ArgumentException("Invalid handle."); } IList <IList <IFCAnyHandle> > outerList = null; IFCData ifcData = handle.GetAttribute(name); if (ifcData.PrimitiveType == IFCDataPrimitiveType.Aggregate) { IFCAggregate outer = ifcData.AsAggregate(); if (outer != null) { outerList = new List <IList <IFCAnyHandle> >(); foreach (IFCData outerVal in outer) { IFCAggregate inner = outerVal.AsAggregate(); if (inner != null) { IList <IFCAnyHandle> innerList = new List <IFCAnyHandle>(); foreach (IFCData innerVal in inner) { innerList.Add(innerVal.AsInstance()); } outerList.Add(innerList); } } } } return(outerList); }
protected static IFCAnyHandle CreateCommonProperty(IFCFile file, string propertyName, IFCData valueData, PropertyValueType valueType, string unitTypeKey) { switch (valueType) { case PropertyValueType.EnumeratedValue: { IList<IFCData> valueList = new List<IFCData>(); valueList.Add(valueData); return IFCInstanceExporter.CreatePropertyEnumeratedValue(file, propertyName, null, valueList, null); } case PropertyValueType.SingleValue: { if (unitTypeKey != null) return IFCInstanceExporter.CreatePropertySingleValue(file, propertyName, null, valueData, ExporterCacheManager.UnitsCache[unitTypeKey]); else return IFCInstanceExporter.CreatePropertySingleValue(file, propertyName, null, valueData, null); } default: throw new InvalidOperationException("Missing case!"); } }
/// <summary> /// Gets an arbitrary enumeration attribute. /// </summary> /// <remarks> /// This function returns the string value of the enumeration. It must be then manually /// converted to the appropriate enum value by the called. /// </remarks> /// <param name="name">The handle.</param> /// <param name="name">The attribute name.</param> /// <returns>The string.</returns> public static string GetEnumerationAttribute(IFCAnyHandle hnd, string name) { if (hnd == null) { throw new ArgumentNullException("hnd"); } if (!hnd.HasValue) { throw new ArgumentException("Invalid handle."); } IFCData ifcData = hnd.GetAttribute(name); if (ifcData.PrimitiveType == IFCDataPrimitiveType.Enumeration) { return(ifcData.AsString()); } return(null); }
/// <summary> /// Constructs a IFCPropertyValue object. /// </summary> /// <param name="ifcSimpleProperty">The property.</param> /// <param name="value">The value.</param> public IFCPropertyValue(IFCSimpleProperty ifcSimpleProperty, IFCData value) { m_IFCSimpleProperty = ifcSimpleProperty; m_Value = value; }
/// <summary> /// Creates a handle representing an IfcCurveStyle and assigns it to the file. /// </summary> /// <param name="file">The file.</param> /// <param name="name">The name.</param> /// <param name="font">A curve style font which is used to present a curve.</param> /// <param name="width">A positive length measure in units of the presentation area for the width of a presented curve.</param> /// <param name="colour">The colour of the visible part of the curve.</param> /// <returns>The handle.</returns> public static IFCAnyHandle CreateCurveStyle(IFCFile file, string name, IFCAnyHandle font, IFCData width, IFCAnyHandle colour) { IFCAnyHandleUtil.ValidateSubTypeOf(font, true, IFCEntityType.IfcPreDefinedCurveFont, IFCEntityType.IfcCurveStyleFont, IFCEntityType.IfcCurveStyleFontAndScaling); IFCAnyHandleUtil.ValidateSubTypeOf(colour, true, IFCEntityType.IfcColourSpecification, IFCEntityType.IfcPreDefinedColour); IFCAnyHandle curveStyle = CreateInstance(file, IFCEntityType.IfcCurveStyle); SetPresentationStyle(curveStyle, name); IFCAnyHandleUtil.SetAttribute(curveStyle, "CurveFont", font); IFCAnyHandleUtil.SetAttribute(curveStyle, "CurveWidth", width); IFCAnyHandleUtil.SetAttribute(curveStyle, "CurveColour", colour); return curveStyle; }
/// <summary> /// Creates a handle representing an IfcSurfaceStyleRendering and assigns it to the file. /// </summary> /// <param name="file">The file.</param> /// <param name="surfaceColour">The optional surface colour.</param> /// <param name="transparency">The optional transparency.</param> /// <param name="diffuseColour">The optional diffuse colour, as a handle or normalised ratio.</param> /// <param name="transmissionColour">The optional transmission colour, as a handle or normalised ratio.</param> /// <param name="diffuseTransmissionColour">The optional diffuse transmission colour, as a handle or normalised ratio.</param> /// <param name="reflectionColour">The optional reflection colour, as a handle or normalised ratio.</param> /// <param name="specularColour">The optional specular colour, as a handle or normalised ratio.</param> /// <param name="specularHighlight">The optional specular highlight, as a handle or normalised ratio.</param> /// <param name="method">The reflectance method.</param> /// <returns>The handle.</returns> public static IFCAnyHandle CreateSurfaceStyleRendering(IFCFile file, IFCAnyHandle surfaceColour, double? transparency, IFCData diffuseColour, IFCData transmissionColour, IFCData diffuseTransmissionColour, IFCData reflectionColour, IFCData specularColour, IFCData specularHighlight, IFCReflectanceMethod method) { ValidSurfaceStyleShading(surfaceColour); IFCAnyHandle surfaceStyleRendering = CreateInstance(file, IFCEntityType.IfcSurfaceStyleRendering); SetSurfaceStyleShading(surfaceStyleRendering, surfaceColour); IFCAnyHandleUtil.SetAttribute(surfaceStyleRendering, "Transparency", transparency); IFCAnyHandleUtil.SetAttribute(surfaceStyleRendering, "DiffuseColour", diffuseColour); IFCAnyHandleUtil.SetAttribute(surfaceStyleRendering, "TransmissionColour", transmissionColour); IFCAnyHandleUtil.SetAttribute(surfaceStyleRendering, "DiffuseTransmissionColour", diffuseTransmissionColour); IFCAnyHandleUtil.SetAttribute(surfaceStyleRendering, "ReflectionColour", reflectionColour); IFCAnyHandleUtil.SetAttribute(surfaceStyleRendering, "SpecularColour", specularColour); IFCAnyHandleUtil.SetAttribute(surfaceStyleRendering, "SpecularHighlight", specularHighlight); IFCAnyHandleUtil.SetAttribute(surfaceStyleRendering, "ReflectanceMethod", method); return surfaceStyleRendering; }
/// <summary> /// Creates an IfcPropertySingleValue and assigns it to the file. /// </summary> /// <param name="file">The file.</param> /// <param name="name">The name.</param> /// <param name="description">The description.</param> /// <param name="nominalValue">The value of the property.</param> /// <param name="unit">The unit.</param> /// <returns>The handle.</returns> public static IFCAnyHandle CreatePropertySingleValue(IFCFile file, string name, string description, IFCData nominalValue, IFCAnyHandle unit) { ValidateProperty(name, description); IFCAnyHandleUtil.ValidateSubTypeOf(unit, true, IFCEntityType.IfcDerivedUnit, IFCEntityType.IfcNamedUnit, IFCEntityType.IfcMonetaryUnit); IFCAnyHandle propertySingleValue = CreateInstance(file, IFCEntityType.IfcPropertySingleValue); IFCAnyHandleUtil.SetAttribute(propertySingleValue, "NominalValue", nominalValue); IFCAnyHandleUtil.SetAttribute(propertySingleValue, "Unit", unit); SetProperty(propertySingleValue, name, description); return propertySingleValue; }
/// <summary> /// Creates an IfcTextStyleFontModel and assigns it to the file. /// </summary> /// <param name="file">The file.</param> /// <param name="name">The name.</param> /// <param name="fontFamily">The font family.</param> /// <param name="fontStyle">The font style.</param> /// <param name="fontVariant">The font variant.</param> /// <param name="fontWeight">The font weight.</param> /// <param name="fontSize">The font size.</param> /// <returns>The handle.</returns> public static IFCAnyHandle CreateTextStyleFontModel(IFCFile file, string name, IList<string> fontFamily, string fontStyle, string fontVariant, string fontWeight, IFCData fontSize) { ValidatePreDefinedItem(name); if (fontSize == null) throw new ArgumentNullException("fontSize"); IFCAnyHandle textStyleFontModel = CreateInstance(file, IFCEntityType.IfcTextStyleFontModel); IFCAnyHandleUtil.SetAttribute(textStyleFontModel, "FontFamily", fontFamily); IFCAnyHandleUtil.SetAttribute(textStyleFontModel, "FontStyle", fontStyle); IFCAnyHandleUtil.SetAttribute(textStyleFontModel, "FontVariant", fontVariant); IFCAnyHandleUtil.SetAttribute(textStyleFontModel, "FontWeight", fontWeight); IFCAnyHandleUtil.SetAttribute(textStyleFontModel, "FontSize", fontSize); SetPreDefinedItem(textStyleFontModel, name); return textStyleFontModel; }
/// <summary> /// Creates a handle representing an IfcMeasureWithUnit and assigns it to the file. /// </summary> /// <param name="file">The file.</param> /// <param name="valueComponent">The value of the physical quantity when expressed in the specified units.</param> /// <param name="unitComponent">The unit in which the physical quantity is expressed.</param> /// <returns>The handle.</returns> public static IFCAnyHandle CreateMeasureWithUnit(IFCFile file, IFCData valueComponent, IFCAnyHandle unitComponent) { if (valueComponent == null) throw new ArgumentNullException("valueComponent"); IFCAnyHandleUtil.ValidateSubTypeOf(unitComponent, false, IFCEntityType.IfcDerivedUnit, IFCEntityType.IfcNamedUnit, IFCEntityType.IfcMonetaryUnit); IFCAnyHandle measureWithUnit = CreateInstance(file, IFCEntityType.IfcMeasureWithUnit); IFCAnyHandleUtil.SetAttribute(measureWithUnit, "ValueComponent", valueComponent); IFCAnyHandleUtil.SetAttribute(measureWithUnit, "UnitComponent", unitComponent); return measureWithUnit; }
/// <summary> /// Gets the unit type from an IFC data. /// </summary> /// <param name="data">The IFC data.</param> /// <param name="defaultType">The default value, if no type is found.</param> /// <returns>The unit type.</returns> public static UnitType GetUnitTypeFromData(IFCData data, UnitType defaultType) { string propertyType; return GetUnitTypeFromData(data, defaultType, out propertyType); }
/// <summary> /// Gets the unit type from an IFC data. /// </summary> /// <param name="data">The IFC data.</param> /// <param name="defaultType">The default value, if no type is found.</param> /// <param name="propertyType">The string value of the simple type, returned for logging purposes.</param> /// <returns>The unit type.</returns> public static UnitType GetUnitTypeFromData(IFCData data, UnitType defaultType, out string propertyType) { UnitType unitType = UnitType.UT_Undefined; if (data.HasSimpleType()) { propertyType = data.GetSimpleType(); if (!MeasureCache.TryGetValue(propertyType, out unitType)) unitType = defaultType; } else { propertyType = ""; unitType = defaultType; } return unitType; }
/// <summary> /// Processes an IFC physical simple quantity. /// </summary> /// <param name="ifcPhysicalQuantity">The IfcPhysicalSimpleQuantity object.</param> /// <returns>The IFCPhysicalSimpleQuantity object.</returns> override protected void Process(IFCAnyHandle ifcPhysicalSimpleQuantity) { base.Process(ifcPhysicalSimpleQuantity); IFCAnyHandle unit = IFCImportHandleUtil.GetOptionalInstanceAttribute(ifcPhysicalSimpleQuantity, "Unit"); if (!IFCAnyHandleUtil.IsNullOrHasNoValue(unit)) IFCUnit = IFCUnit.ProcessIFCUnit(unit); // Process subtypes of IfcPhysicalSimpleQuantity here. string attributeName = ifcPhysicalSimpleQuantity.TypeName.Substring(11) + "Value"; Value = ifcPhysicalSimpleQuantity.GetAttribute(attributeName); BaseUnitType = IFCDataUtil.GetUnitTypeFromData(Value, UnitType.UT_Undefined); if (BaseUnitType == UnitType.UT_Undefined) { // Determine it from the attributeName. if (string.Compare(attributeName, "LengthValue", true) == 0) BaseUnitType = UnitType.UT_Length; else if (string.Compare(attributeName, "AreaValue", true) == 0) BaseUnitType = UnitType.UT_Area; else if (string.Compare(attributeName, "VolumeValue", true) == 0) BaseUnitType = UnitType.UT_Volume; else if (string.Compare(attributeName, "CountValue", true) == 0) BaseUnitType = UnitType.UT_Number; else if (string.Compare(attributeName, "WeightValue", true) == 0) BaseUnitType = UnitType.UT_Mass; else if (string.Compare(attributeName, "TimeValue", true) == 0) BaseUnitType = UnitType.UT_Number; // No time unit type in Revit. else { Importer.TheLog.LogWarning(Id, "Can't determine unit type for IfcPhysicalSimpleQuantity of type: " + attributeName, true); BaseUnitType = UnitType.UT_Number; } } if (IFCUnit == null) IFCUnit = IFCImportFile.TheFile.IFCUnits.GetIFCProjectUnit(BaseUnitType); }
/// <summary> /// Creates the related IfcCurveStyle for a representation item. /// </summary> /// <param name="exporterIFC">The exporter.</param> /// <param name="repItemHnd">The representation item.</param> /// <param name="curveWidth">The curve width.</param> /// <param name="colorHnd">The curve color handle.</param> /// <returns>The IfcCurveStyle handle.</returns> public static IFCAnyHandle CreateCurveStyleForRepItem(ExporterIFC exporterIFC, IFCAnyHandle repItemHnd, IFCData curveWidth, IFCAnyHandle colorHnd) { if (repItemHnd == null) return null; IFCAnyHandle presStyleHnd = null; IFCFile file = exporterIFC.GetFile(); IFCAnyHandle curveStyleHnd = IFCInstanceExporter.CreateCurveStyle(file, null, null, curveWidth, colorHnd); ISet<IFCAnyHandle> styles = new HashSet<IFCAnyHandle>(); styles.Add(curveStyleHnd); presStyleHnd = IFCInstanceExporter.CreatePresentationStyleAssignment(file, styles); HashSet<IFCAnyHandle> presStyleSet = new HashSet<IFCAnyHandle>(); presStyleSet.Add(presStyleHnd); return IFCInstanceExporter.CreateStyledItem(file, repItemHnd, presStyleSet, null); }
private double? GetTrimParameter(IFCData trim, IFCCurve basisCurve, IFCTrimmingPreference trimPreference, bool secondAttempt) { bool preferParam = !(trimPreference == IFCTrimmingPreference.Cartesian); if (secondAttempt) preferParam = !preferParam; double vertexEps = IFCImportFile.TheFile.Document.Application.VertexTolerance; IFCAggregate trimAggregate = trim.AsAggregate(); foreach (IFCData trimParam in trimAggregate) { if (!preferParam && (trimParam.PrimitiveType == IFCDataPrimitiveType.Instance)) { IFCAnyHandle trimParamInstance = trimParam.AsInstance(); XYZ trimParamPt = IFCPoint.ProcessScaledLengthIFCCartesianPoint(trimParamInstance); if (trimParamPt == null) { Importer.TheLog.LogWarning(basisCurve.Id, "Invalid trim point for basis curve.", false); continue; } try { IntersectionResult result = basisCurve.Curve.Project(trimParamPt); if (result.Distance < vertexEps) return result.Parameter; Importer.TheLog.LogWarning(basisCurve.Id, "Cartesian value for trim point not on the basis curve.", false); } catch { Importer.TheLog.LogWarning(basisCurve.Id, "Cartesian value for trim point not on the basis curve.", false); } } else if (preferParam && (trimParam.PrimitiveType == IFCDataPrimitiveType.Double)) { double trimParamDouble = trimParam.AsDouble(); if (basisCurve.Curve.IsCyclic) trimParamDouble = IFCUnitUtil.ScaleAngle(trimParamDouble); else trimParamDouble = IFCUnitUtil.ScaleLength(trimParamDouble); return trimParamDouble; } } // Try again with opposite preference. if (!secondAttempt) return GetTrimParameter(trim, basisCurve, trimPreference, true); return null; }
private void GetTrimParameters(IFCData trim1, IFCData trim2, IFCCurve basisCurve, IFCTrimmingPreference trimPreference, out double param1, out double param2) { double? condParam1 = GetTrimParameter(trim1, basisCurve, trimPreference, false); if (!condParam1.HasValue) throw new InvalidOperationException("#" + basisCurve.Id + ": Couldn't apply first trimming parameter of IfcTrimmedCurve."); param1 = condParam1.Value; double? condParam2 = GetTrimParameter(trim2, basisCurve, trimPreference, false); if (!condParam2.HasValue) throw new InvalidOperationException("#" + basisCurve.Id + ": Couldn't apply second trimming parameter of IfcTrimmedCurve."); param2 = condParam2.Value; if (MathUtil.IsAlmostEqual(param1, param2)) { // If we had a cartesian parameter as the trim preference, check if the parameter values are better. if (trimPreference == IFCTrimmingPreference.Cartesian) { condParam1 = GetTrimParameter(trim1, basisCurve, IFCTrimmingPreference.Parameter, true); if (!condParam1.HasValue) throw new InvalidOperationException("#" + basisCurve.Id + ": Couldn't apply first trimming parameter of IfcTrimmedCurve."); param1 = condParam1.Value; condParam2 = GetTrimParameter(trim2, basisCurve, IFCTrimmingPreference.Parameter, true); if (!condParam2.HasValue) throw new InvalidOperationException("#" + basisCurve.Id + ": Couldn't apply second trimming parameter of IfcTrimmedCurve."); param2 = condParam2.Value; } else throw new InvalidOperationException("#" + basisCurve.Id + ": Ignoring 0 length curve."); } }