/// <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.SchemaVersionAtLeast(IFCSchemaVersion.IFC4Obsolete)) ? 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 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); }
/// <summary> /// Processes measure with unit. /// </summary> /// <param name="measureUnitHnd">The measure unit handle.</param> void ProcessIFCMeasureWithUnit(IFCAnyHandle measureUnitHnd) { double baseScale = 0.0; IFCData ifcData = measureUnitHnd.GetAttribute("ValueComponent"); if (!ifcData.HasValue) { throw new InvalidOperationException("#" + measureUnitHnd.StepId + ": Missing required attribute ValueComponent."); } if (ifcData.PrimitiveType == IFCDataPrimitiveType.Double) { baseScale = ifcData.AsDouble(); } else if (ifcData.PrimitiveType == IFCDataPrimitiveType.Integer) { baseScale = (double)ifcData.AsInteger(); } if (MathUtil.IsAlmostZero(baseScale)) { throw new InvalidOperationException("#" + measureUnitHnd.StepId + ": ValueComponent should not be almost zero."); } IFCAnyHandle unitHnd = IFCImportHandleUtil.GetRequiredInstanceAttribute(measureUnitHnd, "UnitComponent", true); IFCUnit unit = ProcessIFCUnit(unitHnd); CopyUnit(unit); ScaleFactor = unit.ScaleFactor * baseScale; }
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 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 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 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 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> /// 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> /// 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> /// 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); }
/// <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> /// Checks if an object handle has IfcRelDecomposes. /// </summary> /// <param name="objectHandle">The object handle.</param> /// <returns>True if it has, false if not.</returns> public static bool HasRelDecomposes(IFCAnyHandle objectHandle) { if (objectHandle == null) { throw new ArgumentNullException("objectHandle"); } if (!objectHandle.HasValue) { throw new ArgumentException("Invalid handle."); } if (!IsSubTypeOf(objectHandle, IFCEntityType.IfcObject) && !IsSubTypeOf(objectHandle, IFCEntityType.IfcTypeObject)) { throw new ArgumentException("The operation is not valid for this handle."); } IFCData ifcData = objectHandle.GetAttribute("Decomposes"); if (!ifcData.HasValue) { return(false); } else if (ifcData.PrimitiveType == IFCDataPrimitiveType.Aggregate) { IFCAggregate aggregate = ifcData.AsAggregate(); if (aggregate != null && aggregate.Count > 0) { return(true); } else { return(false); } } throw new InvalidOperationException("Failed to get decomposes."); }
/// <summary> /// Gets the coordinates of an IfcCartesianPoint. /// </summary> /// <param name="axisPlacement">The IfcCartesianPoint.</param> /// <returns>The list of coordinates.</returns> public static IList <double> GetCoordinates(IFCAnyHandle cartesianPoint) { IList <double> coordinates = null; if (cartesianPoint == null) { throw new ArgumentNullException("cartesianPoint"); } if (!cartesianPoint.HasValue) { throw new ArgumentException("Invalid handle."); } if (!IsSubTypeOf(cartesianPoint, IFCEntityType.IfcCartesianPoint)) { throw new ArgumentException("Not an IfcCartesianPoint handle."); } IFCData ifcData = cartesianPoint.GetAttribute("Coordinates"); if (ifcData.PrimitiveType == IFCDataPrimitiveType.Aggregate) { IFCAggregate aggregate = ifcData.AsAggregate(); if (aggregate != null && aggregate.Count > 0) { coordinates = new List <double>(); foreach (IFCData val in aggregate) { if (val.PrimitiveType == IFCDataPrimitiveType.Double) { coordinates.Add(val.AsDouble()); } } } } return(coordinates); }
/// <summary> /// Gets IfcRelDecomposes of an object handle. /// </summary> /// <param name="objectHandle">The object handle.</param> /// <returns>The collection of IfcRelDecomposes.</returns> public static HashSet <IFCAnyHandle> GetRelDecomposes(IFCAnyHandle objectHandle) { if (objectHandle == null) { throw new ArgumentNullException("objectHandle"); } if (!objectHandle.HasValue) { throw new ArgumentException("Invalid handle."); } if (!IsSubTypeOf(objectHandle, IFCEntityType.IfcObject) && !IsSubTypeOf(objectHandle, IFCEntityType.IfcTypeObject)) { throw new ArgumentException("The operation is not valid for this handle."); } HashSet <IFCAnyHandle> decomposes = new HashSet <IFCAnyHandle>(); IFCData ifcData = objectHandle.GetAttribute("IsDecomposedBy"); if (ifcData.PrimitiveType == IFCDataPrimitiveType.Aggregate) { IFCAggregate aggregate = ifcData.AsAggregate(); if (aggregate != null && aggregate.Count > 0) { foreach (IFCData val in aggregate) { if (val.PrimitiveType == IFCDataPrimitiveType.Instance) { decomposes.Add(val.AsInstance()); } } } } return(decomposes); }
/// <summary> /// Gets IfcMaterialDefinitionRepresentation inverse set of an IfcMaterial handle. /// </summary> /// <param name="objectHandle">The IfcMaterial handle.</param> /// <returns>The collection of IfcMaterialDefinitionRepresentation.</returns> public static HashSet <IFCAnyHandle> GetHasRepresentation(IFCAnyHandle objectHandle) { if (objectHandle == null) { throw new ArgumentNullException("objectHandle"); } if (!objectHandle.HasValue) { throw new ArgumentException("Invalid handle."); } if (!IsSubTypeOf(objectHandle, IFCEntityType.IfcMaterial)) { throw new ArgumentException("The operation is not valid for this handle."); } HashSet <IFCAnyHandle> hasRepresentation = new HashSet <IFCAnyHandle>(); IFCData ifcData = objectHandle.GetAttribute("HasRepresentation"); if (ifcData.PrimitiveType == IFCDataPrimitiveType.Aggregate) { IFCAggregate aggregate = ifcData.AsAggregate(); if (aggregate != null && aggregate.Count > 0) { foreach (IFCData val in aggregate) { if (val.PrimitiveType == IFCDataPrimitiveType.Instance) { hasRepresentation.Add(val.AsInstance()); } } } } return(hasRepresentation); }
/// <summary> /// Gets representations of a representation handle. /// </summary> /// <param name="representation">The representation handle.</param> /// <returns>The list of representations.</returns> public static List <IFCAnyHandle> GetRepresentations(IFCAnyHandle representation) { if (representation == null) { throw new ArgumentNullException("representation"); } if (!representation.HasValue) { throw new ArgumentException("Invalid handle."); } if (!IsSubTypeOf(representation, IFCEntityType.IfcProductRepresentation)) { throw new ArgumentException("The operation is not valid for this handle."); } List <IFCAnyHandle> representations = new List <IFCAnyHandle>(); IFCData ifcData = representation.GetAttribute("Representations"); if (ifcData.PrimitiveType == IFCDataPrimitiveType.Aggregate) { IFCAggregate aggregate = ifcData.AsAggregate(); if (aggregate != null && aggregate.Count > 0) { foreach (IFCData val in aggregate) { if (val.PrimitiveType == IFCDataPrimitiveType.Instance) { representations.Add(val.AsInstance()); } } } } return(representations); }
/// <summary> /// Processes an IFC property single value. /// </summary> /// <param name="propertySingleValue">The IfcPropertySingleValue object.</param> void ProcessIFCPropertySingleValue(IFCAnyHandle propertySingleValue) { IFCPropertyValues.Add(new IFCPropertyValue(this, propertySingleValue.GetAttribute("NominalValue"))); ProcessIFCSimplePropertyUnit(this, propertySingleValue); }
override protected void Process(IFCAnyHandle item) { base.Process(item); IFCAnyHandle surfaceColour = IFCImportHandleUtil.GetRequiredInstanceAttribute(item, "SurfaceColour", false); if (!IFCAnyHandleUtil.IsNullOrHasNoValue(surfaceColour)) { m_SurfaceColour = IFCColourRgb.ProcessIFCColourRgb(surfaceColour); } if (IFCAnyHandleUtil.IsSubTypeOf(item, IFCEntityType.IfcSurfaceStyleRendering)) { Transparency = IFCImportHandleUtil.GetOptionalNormalisedRatioAttribute(item, "Transparency", 0.0); IFCData diffuseColour = item.GetAttribute("DiffuseColour"); if (diffuseColour.PrimitiveType == IFCDataPrimitiveType.Instance) { m_DiffuseColour = IFCColourRgb.ProcessIFCColourRgb(diffuseColour.AsInstance()); } else if (diffuseColour.PrimitiveType == IFCDataPrimitiveType.Double) { m_DiffuseColourFactor = diffuseColour.AsDouble(); } IFCData transmissionColour = item.GetAttribute("TransmissionColour"); if (transmissionColour.PrimitiveType == IFCDataPrimitiveType.Instance) { m_TransmissionColour = IFCColourRgb.ProcessIFCColourRgb(transmissionColour.AsInstance()); } else if (transmissionColour.PrimitiveType == IFCDataPrimitiveType.Double) { m_TransmissionColourFactor = transmissionColour.AsDouble(); } IFCData diffuseTransmissionColour = item.GetAttribute("DiffuseTransmissionColour"); if (transmissionColour.PrimitiveType == IFCDataPrimitiveType.Instance) { m_DiffuseTransmissionColour = IFCColourRgb.ProcessIFCColourRgb(diffuseTransmissionColour.AsInstance()); } else if (transmissionColour.PrimitiveType == IFCDataPrimitiveType.Double) { m_DiffuseTransmissionColourFactor = diffuseTransmissionColour.AsDouble(); } IFCData reflectionColour = item.GetAttribute("ReflectionColour"); if (reflectionColour.PrimitiveType == IFCDataPrimitiveType.Instance) { m_ReflectionColour = IFCColourRgb.ProcessIFCColourRgb(reflectionColour.AsInstance()); } else if (reflectionColour.PrimitiveType == IFCDataPrimitiveType.Double) { m_ReflectionColourFactor = reflectionColour.AsDouble(); } IFCData specularColour = item.GetAttribute("SpecularColour"); if (specularColour.PrimitiveType == IFCDataPrimitiveType.Instance) { m_SpecularColour = IFCColourRgb.ProcessIFCColourRgb(specularColour.AsInstance()); } else if (specularColour.PrimitiveType == IFCDataPrimitiveType.Double) { m_SpecularColourFactor = specularColour.AsDouble(); } IFCData specularHighlight = item.GetAttribute("SpecularHighlight"); if (specularHighlight.PrimitiveType == IFCDataPrimitiveType.Double) { try { string simpleType = specularHighlight.GetSimpleType(); if (string.Compare(simpleType, "IfcSpecularExponent", true) == 0) { m_SpecularExponent = specularHighlight.AsDouble(); } else if (string.Compare(simpleType, "IfcSpecularRoughness", true) == 0) { m_SpecularRoughness = specularHighlight.AsDouble(); } else { Importer.TheLog.LogError(item.StepId, "Unknown type of specular highlight, ignoring.", false); } } catch { Importer.TheLog.LogError(item.StepId, "Unspecified type of specular highlight, ignoring.", false); } } else if (specularHighlight.HasValue) { Importer.TheLog.LogError(item.StepId, "Unknown type of specular highlight, ignoring.", false); } } }
protected override void Process(IFCAnyHandle ifcCurve) { base.Process(ifcCurve); bool found = false; bool sameSense = IFCImportHandleUtil.GetRequiredBooleanAttribute(ifcCurve, "SenseAgreement", out found); if (!found) { sameSense = true; } IFCAnyHandle basisCurve = IFCImportHandleUtil.GetRequiredInstanceAttribute(ifcCurve, "BasisCurve", true); IFCCurve ifcBasisCurve = IFCCurve.ProcessIFCCurve(basisCurve); if (ifcBasisCurve == null || (ifcBasisCurve.IsEmpty())) { // LOG: ERROR: Error processing BasisCurve # for IfcTrimmedCurve #. return; } if (ifcBasisCurve.Curve == null) { // LOG: ERROR: Expected a single curve, not a curve loop for BasisCurve # for IfcTrimmedCurve #. return; } IFCData trim1 = ifcCurve.GetAttribute("Trim1"); if (trim1.PrimitiveType != IFCDataPrimitiveType.Aggregate) { // LOG: ERROR: Invalid data type for Trim1 attribute for IfcTrimmedCurve #. return; } IFCData trim2 = ifcCurve.GetAttribute("Trim2"); if (trim2.PrimitiveType != IFCDataPrimitiveType.Aggregate) { // LOG: ERROR: Invalid data type for Trim1 attribute for IfcTrimmedCurve #. return; } // Note that these are the "unprocessed" values. These can be used for, e.g., adding up the IFC parameter length // of the file, to account for export errors. The "processed" values can be determined from the Revit curves. Trim1 = GetRawTrimParameter(trim1); Trim2 = GetRawTrimParameter(trim2); IFCTrimmingPreference trimPreference = IFCEnums.GetSafeEnumerationAttribute <IFCTrimmingPreference>(ifcCurve, "MasterRepresentation", IFCTrimmingPreference.Parameter); double param1 = 0.0, param2 = 0.0; Curve baseCurve = ifcBasisCurve.Curve; try { GetTrimParameters(ifcBasisCurve.Id, trim1, trim2, baseCurve, trimPreference, out param1, out param2); if (NeedToReverseBaseCurve(baseCurve, param1, param2, trimPreference)) { Importer.TheLog.LogWarning(Id, "Invalid Param1 > Param2 for non-cyclic IfcTrimmedCurve using Cartesian trimming preference, reversing.", false); baseCurve = baseCurve.CreateReversed(); GetTrimParameters(ifcBasisCurve.Id, trim1, trim2, baseCurve, trimPreference, out param1, out param2); } } catch (Exception ex) { Importer.TheLog.LogError(ifcCurve.StepId, ex.Message, false); return; } if (MathUtil.IsAlmostEqual(param1, param2)) { Importer.TheLog.LogError(Id, "Param1 = Param2 for IfcTrimmedCurve #, ignoring.", false); return; } Curve curve = null; if (baseCurve.IsCyclic) { double period = baseCurve.Period; if (!sameSense) { MathUtil.Swap(ref param1, ref param2); } // We want to make sure both values are within period of one another. param1 = MathUtil.PutInRange(param1, 0, period); param2 = MathUtil.PutInRange(param2, 0, period); if (param2 < param1) { param2 = MathUtil.PutInRange(param2, param1 + period / 2, period); } // This is effectively an unbound curve. double numberOfPeriods = (param2 - param1) / period; if (MathUtil.IsAlmostEqual(numberOfPeriods, Math.Round(numberOfPeriods))) { Importer.TheLog.LogWarning(Id, "Start and end parameters indicate a zero-length closed curve, assuming unbound is intended.", false); curve = baseCurve; } else { curve = baseCurve.Clone(); if (!SafelyBoundCurve(curve, param1, param2)) { return; } } } else { if (param1 > param2 - MathUtil.Eps()) { Importer.TheLog.LogWarning(Id, "Param1 > Param2 for IfcTrimmedCurve #, reversing.", false); MathUtil.Swap(ref param1, ref param2); sameSense = !sameSense; } Curve copyCurve = baseCurve.Clone(); double length = param2 - param1; if (length <= IFCImportFile.TheFile.ShortCurveTolerance) { string lengthAsString = IFCUnitUtil.FormatLengthAsString(length); Importer.TheLog.LogError(Id, "curve length of " + lengthAsString + " is invalid, ignoring.", false); return; } if (!SafelyBoundCurve(copyCurve, param1, param2)) { return; } if (sameSense) { curve = copyCurve; } else { curve = copyCurve.CreateReversed(); } } CurveLoop curveLoop = new CurveLoop(); curveLoop.Append(curve); SetCurveLoop(curveLoop); }
protected override void Process(IFCAnyHandle ifcCurve) { base.Process(ifcCurve); bool found = false; bool sameSense = IFCImportHandleUtil.GetRequiredBooleanAttribute(ifcCurve, "SenseAgreement", out found); if (!found) { sameSense = true; } IFCAnyHandle basisCurve = IFCImportHandleUtil.GetRequiredInstanceAttribute(ifcCurve, "BasisCurve", true); IFCCurve ifcBasisCurve = IFCCurve.ProcessIFCCurve(basisCurve); if (ifcBasisCurve == null || (ifcBasisCurve.Curve == null && ifcBasisCurve.CurveLoop == null)) { // LOG: ERROR: Error processing BasisCurve # for IfcTrimmedCurve #. return; } if (ifcBasisCurve.Curve == null) { // LOG: ERROR: Expected a single curve, not a curve loop for BasisCurve # for IfcTrimmedCurve #. return; } IFCData trim1 = ifcCurve.GetAttribute("Trim1"); if (trim1.PrimitiveType != IFCDataPrimitiveType.Aggregate) { // LOG: ERROR: Invalid data type for Trim1 attribute for IfcTrimmedCurve #. return; } IFCData trim2 = ifcCurve.GetAttribute("Trim2"); if (trim2.PrimitiveType != IFCDataPrimitiveType.Aggregate) { // LOG: ERROR: Invalid data type for Trim1 attribute for IfcTrimmedCurve #. return; } IFCTrimmingPreference trimPreference = IFCEnums.GetSafeEnumerationAttribute <IFCTrimmingPreference>(ifcCurve, "MasterRepresentation", IFCTrimmingPreference.Parameter); double param1 = 0.0, param2 = 0.0; try { GetTrimParameters(trim1, trim2, ifcBasisCurve, trimPreference, out param1, out param2); } catch (Exception ex) { Importer.TheLog.LogError(ifcCurve.StepId, ex.Message, false); return; } Curve baseCurve = ifcBasisCurve.Curve; if (baseCurve.IsCyclic) { if (!sameSense) { MathUtil.Swap(ref param1, ref param2); } if (param2 < param1) { param2 = MathUtil.PutInRange(param2, param1 + Math.PI, 2 * Math.PI); } if (param2 - param1 > 2.0 * Math.PI - MathUtil.Eps()) { Importer.TheLog.LogWarning(ifcCurve.StepId, "IfcTrimmedCurve length is greater than 2*PI, leaving unbound.", false); Curve = baseCurve; return; } Curve = baseCurve.Clone(); try { Curve.MakeBound(param1, param2); } catch (Exception ex) { if (ex.Message.Contains("too small")) { Curve = null; Importer.TheLog.LogError(Id, "curve length is invalid, ignoring.", false); return; } else { throw ex; } } } else { if (MathUtil.IsAlmostEqual(param1, param2)) { Importer.TheLog.LogError(Id, "Param1 = Param2 for IfcTrimmedCurve #, ignoring.", false); return; } if (param1 > param2 - MathUtil.Eps()) { Importer.TheLog.LogWarning(Id, "Param1 > Param2 for IfcTrimmedCurve #, reversing.", false); MathUtil.Swap(ref param1, ref param2); return; } Curve copyCurve = baseCurve.Clone(); double length = param2 - param1; if (length <= IFCImportFile.TheFile.Document.Application.ShortCurveTolerance) { string lengthAsString = IFCUnitUtil.FormatLengthAsString(length); Importer.TheLog.LogError(Id, "curve length of " + lengthAsString + " is invalid, ignoring.", false); return; } copyCurve.MakeBound(param1, param2); if (sameSense) { Curve = copyCurve; } else { Curve = copyCurve.CreateReversed(); } } CurveLoop = new CurveLoop(); CurveLoop.Append(Curve); }
/// <summary> /// Create association (IfcRelAssociatesClassification) between the Element (ElemHnd) and specified classification reference /// </summary> /// <param name="exporterIFC">The exporterIFC class.</param> /// <param name="file">The IFC file class.</param> /// <param name="elemHnd">The corresponding IFC entity handle.</param> /// <param name="classificationReference">The classification reference to be associated with</param> public static void AssociateClassificationReference(ExporterIFC exporterIFC, IFCFile file, IFCAnyHandle elemHnd, IFCAnyHandle classificationReference) { HashSet <IFCAnyHandle> relatedObjects = new HashSet <IFCAnyHandle>(); relatedObjects.Add(elemHnd); IFCAnyHandle relAssociates = IFCInstanceExporter.CreateRelAssociatesClassification(file, GUIDUtil.CreateGUID(), ExporterCacheManager.OwnerHistoryHandle, classificationReference.GetAttribute("ReferencedSource").ToString() + " Classification", "", relatedObjects, classificationReference); }
override protected void Process(IFCAnyHandle item) { base.Process(item); IFCAnyHandle surfaceColour = IFCImportHandleUtil.GetRequiredInstanceAttribute(item, "SurfaceColour", false); if (!IFCAnyHandleUtil.IsNullOrHasNoValue(surfaceColour)) m_SurfaceColour = IFCColourRgb.ProcessIFCColourRgb(surfaceColour); if (IFCAnyHandleUtil.IsSubTypeOf(item, IFCEntityType.IfcSurfaceStyleRendering)) { Transparency = IFCImportHandleUtil.GetOptionalNormalisedRatioAttribute(item, "Transparency", 0.0); IFCData diffuseColour = item.GetAttribute("DiffuseColour"); if (diffuseColour.PrimitiveType == IFCDataPrimitiveType.Instance) m_DiffuseColour = IFCColourRgb.ProcessIFCColourRgb(diffuseColour.AsInstance()); else if (diffuseColour.PrimitiveType == IFCDataPrimitiveType.Double) m_DiffuseColourFactor = diffuseColour.AsDouble(); IFCData transmissionColour = item.GetAttribute("TransmissionColour"); if (transmissionColour.PrimitiveType == IFCDataPrimitiveType.Instance) m_TransmissionColour = IFCColourRgb.ProcessIFCColourRgb(transmissionColour.AsInstance()); else if (transmissionColour.PrimitiveType == IFCDataPrimitiveType.Double) m_TransmissionColourFactor = transmissionColour.AsDouble(); IFCData diffuseTransmissionColour = item.GetAttribute("DiffuseTransmissionColour"); if (transmissionColour.PrimitiveType == IFCDataPrimitiveType.Instance) m_DiffuseTransmissionColour = IFCColourRgb.ProcessIFCColourRgb(diffuseTransmissionColour.AsInstance()); else if (transmissionColour.PrimitiveType == IFCDataPrimitiveType.Double) m_DiffuseTransmissionColourFactor = diffuseTransmissionColour.AsDouble(); IFCData reflectionColour = item.GetAttribute("ReflectionColour"); if (reflectionColour.PrimitiveType == IFCDataPrimitiveType.Instance) m_ReflectionColour = IFCColourRgb.ProcessIFCColourRgb(reflectionColour.AsInstance()); else if (reflectionColour.PrimitiveType == IFCDataPrimitiveType.Double) m_ReflectionColourFactor = reflectionColour.AsDouble(); IFCData specularColour = item.GetAttribute("SpecularColour"); if (specularColour.PrimitiveType == IFCDataPrimitiveType.Instance) m_SpecularColour = IFCColourRgb.ProcessIFCColourRgb(specularColour.AsInstance()); else if (specularColour.PrimitiveType == IFCDataPrimitiveType.Double) m_SpecularColourFactor = specularColour.AsDouble(); IFCData specularHighlight = item.GetAttribute("SpecularHighlight"); if (specularHighlight.PrimitiveType == IFCDataPrimitiveType.Double) { try { string simpleType = specularHighlight.GetSimpleType(); if (string.Compare(simpleType, "IfcSpecularExponent", true) == 0) m_SpecularExponent = specularHighlight.AsDouble(); else if (string.Compare(simpleType, "IfcSpecularRoughness", true) == 0) m_SpecularRoughness = specularHighlight.AsDouble(); else IFCImportFile.TheLog.LogError(item.StepId, "Unknown type of specular highlight, ignoring.", false); } catch { IFCImportFile.TheLog.LogError(item.StepId, "Unspecified type of specular highlight, ignoring.", false); } } else if (specularHighlight.HasValue) { IFCImportFile.TheLog.LogError(item.StepId, "Unknown type of specular highlight, ignoring.", false); } } }
/// <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> /// Processes an IFC property reference value. /// </summary> /// <param name="propertyReferenceValue">The IfcPropertyReferenceValue object.</param> void ProcessIFCPropertyReferenceValue(IFCAnyHandle propertyReferenceValue) { IFCData referenceValue = propertyReferenceValue.GetAttribute("PropertyReference"); IFCPropertyValues.Add(new IFCPropertyValue(this, referenceValue)); }
/// <summary> /// Exports materials for host object. /// </summary> /// <param name="exporterIFC"> /// The ExporterIFC object. /// </param> /// <param name="hostObject"> /// The host object. /// </param> /// <param name="elemHnds"> /// The host IFC handles. /// </param> /// <param name="geometryElement"> /// The geometry element. /// </param> /// <param name="productWrapper"> /// The IFCProductWrapper. /// </param> /// <param name="levelId"> /// The level id. /// </param> /// <param name="direction"> /// The IFCLayerSetDirection. /// </param> /// <returns> /// True if exported successfully, false otherwise. /// </returns> public static bool ExportHostObjectMaterials(ExporterIFC exporterIFC, HostObject hostObject, IList <IFCAnyHandle> elemHnds, GeometryElement geometryElement, IFCProductWrapper productWrapper, ElementId levelId, Toolkit.IFCLayerSetDirection direction) { if (hostObject == null) { return(true); //nothing to do } if (elemHnds == null || (elemHnds.Count == 0)) { return(true); //nothing to do } IFCFile file = exporterIFC.GetFile(); // Roofs with no components are only allowed one material. We will arbitrarily choose the thickest material. IFCAnyHandle primaryMaterialHnd = null; using (IFCTransaction tr = new IFCTransaction(file)) { if (productWrapper != null) { productWrapper.ClearFinishMaterials(); } double scale = exporterIFC.LinearScale; double scaledOffset = 0.0, scaledWallWidth = 0.0, wallHeight = 0.0; Wall wall = hostObject as Wall; if (wall != null) { scaledWallWidth = wall.Width * scale; scaledOffset = -scaledWallWidth / 2.0; BoundingBoxXYZ boundingBox = wall.get_BoundingBox(null); if (boundingBox != null) { wallHeight = boundingBox.Max.Z - boundingBox.Min.Z; } } ElementId typeElemId = hostObject.GetTypeId(); IFCAnyHandle materialLayerSet = ExporterCacheManager.MaterialLayerSetCache.Find(typeElemId); if (IFCAnyHandleUtil.IsNullOrHasNoValue(materialLayerSet)) { HostObjAttributes hostObjAttr = hostObject.Document.GetElement(typeElemId) as HostObjAttributes; if (hostObjAttr == null) { return(true); //nothing to do } List <ElementId> matIds = new List <ElementId>(); List <double> widths = new List <double>(); List <MaterialFunctionAssignment> functions = new List <MaterialFunctionAssignment>(); ElementId baseMatId = CategoryUtil.GetBaseMaterialIdForElement(hostObject); CompoundStructure cs = hostObjAttr.GetCompoundStructure(); if (cs != null) { //TODO: Vertically compound structures are not yet supported by export. if (!cs.IsVerticallyHomogeneous() && !MathUtil.IsAlmostZero(wallHeight)) { cs = cs.GetSimpleCompoundStructure(wallHeight, wallHeight / 2.0); } for (int i = 0; i < cs.LayerCount; ++i) { ElementId matId = cs.GetMaterialId(i); if (matId != ElementId.InvalidElementId) { matIds.Add(matId); } else { matIds.Add(baseMatId); } widths.Add(cs.GetLayerWidth(i)); // save layer function into IFCProductWrapper, // it's used while exporting "Function" of Pset_CoveringCommon functions.Add(cs.GetLayerFunction(i)); } } if (matIds.Count == 0) { matIds.Add(baseMatId); widths.Add(cs != null ? cs.GetWidth() : 0); functions.Add(MaterialFunctionAssignment.None); } List <IFCAnyHandle> layers = new List <IFCAnyHandle>(); double thickestLayer = 0.0; for (int i = 0; i < matIds.Count; ++i) { if (widths[i] < MathUtil.Eps()) { continue; } IFCAnyHandle materialHnd = CategoryUtil.GetOrCreateMaterialHandle(hostObjAttr.Document, exporterIFC, matIds[i]); if (primaryMaterialHnd == null || (widths[i] > thickestLayer)) { primaryMaterialHnd = materialHnd; thickestLayer = widths[i]; } double scaledWidth = widths[i] * scale; IFCAnyHandle materialLayer = IFCInstanceExporter.CreateMaterialLayer(file, materialHnd, scaledWidth, null); layers.Add(materialLayer); if ((productWrapper != null) && (functions[i] == MaterialFunctionAssignment.Finish1 || functions[i] == MaterialFunctionAssignment.Finish2)) { productWrapper.AddFinishMaterial(materialHnd); } } if (layers.Count == 0) { return(false); } string layerSetName = NamingUtil.CreateIFCFamilyName(exporterIFC, -1); materialLayerSet = IFCInstanceExporter.CreateMaterialLayerSet(file, layers, layerSetName); ExporterCacheManager.MaterialLayerSetCache.Register(typeElemId, materialLayerSet); } // IfcMaterialLayerSetUsage is not supported for IfcWall, only IfcWallStandardCase. IFCAnyHandle layerSetUsage = null; for (int ii = 0; ii < elemHnds.Count; ii++) { IFCAnyHandle elemHnd = elemHnds[ii]; if (IFCAnyHandleUtil.IsNullOrHasNoValue(elemHnd)) { continue; } HashSet <IFCAnyHandle> relDecomposesSet = IFCAnyHandleUtil.GetRelDecomposes(elemHnd); IList <IFCAnyHandle> subElemHnds = new List <IFCAnyHandle>(); if (relDecomposesSet != null && relDecomposesSet.Count == 1) { IFCAnyHandle relAggregates = relDecomposesSet.First(); if (IFCAnyHandleUtil.IsTypeOf(relAggregates, IFCEntityType.IfcRelAggregates)) { IFCData ifcData = relAggregates.GetAttribute("RelatedObjects"); if (ifcData.PrimitiveType == IFCDataPrimitiveType.Aggregate) { IFCAggregate aggregate = ifcData.AsAggregate(); if (aggregate != null && aggregate.Count > 0) { foreach (IFCData val in aggregate) { if (val.PrimitiveType == IFCDataPrimitiveType.Instance) { subElemHnds.Add(val.AsInstance()); } } } } } } bool hasSubElems = !(subElemHnds.Count == 0); bool isRoof = IFCAnyHandleUtil.IsTypeOf(elemHnd, IFCEntityType.IfcRoof); if (!hasSubElems && !isRoof && !IFCAnyHandleUtil.IsTypeOf(elemHnd, IFCEntityType.IfcWall)) { if (layerSetUsage == null) { bool flipDirSense = true; if (wall != null) { // if we have flipped the center curve on export, we need to take that into account here. // We flip the center curve on export if it is an arc and it has a negative Z direction. LocationCurve locCurve = wall.Location as LocationCurve; if (locCurve != null) { Curve curve = locCurve.Curve; Plane defPlane = new Plane(XYZ.BasisX, XYZ.BasisY, XYZ.Zero); bool curveFlipped = GeometryUtil.MustFlipCurve(defPlane, curve); flipDirSense = !(wall.Flipped ^ curveFlipped); } } else if (hostObject is Floor) { flipDirSense = false; } double offsetFromReferenceLine = flipDirSense ? -scaledOffset : scaledOffset; IFCDirectionSense sense = flipDirSense ? IFCDirectionSense.Negative : IFCDirectionSense.Positive; layerSetUsage = IFCInstanceExporter.CreateMaterialLayerSetUsage(file, materialLayerSet, direction, sense, offsetFromReferenceLine); } ExporterCacheManager.MaterialLayerRelationsCache.Add(layerSetUsage, elemHnd); } else { if (hasSubElems) { foreach (IFCAnyHandle subElemHnd in subElemHnds) { if (!IFCAnyHandleUtil.IsNullOrHasNoValue(subElemHnd)) { ExporterCacheManager.MaterialLayerRelationsCache.Add(materialLayerSet, subElemHnd); } } } else if (!isRoof) { ExporterCacheManager.MaterialLayerRelationsCache.Add(materialLayerSet, elemHnd); } else if (primaryMaterialHnd != null) { ExporterCacheManager.MaterialLayerRelationsCache.Add(primaryMaterialHnd, elemHnd); } } exporterIFC.RegisterSpaceBoundingElementHandle(elemHnd, hostObject.Id, levelId); } tr.Commit(); return(true); } }
protected override void Process(IFCAnyHandle ifcCurve) { base.Process(ifcCurve); bool found = false; bool sameSense = IFCImportHandleUtil.GetRequiredBooleanAttribute(ifcCurve, "SenseAgreement", out found); if (!found) sameSense = true; IFCAnyHandle basisCurve = IFCImportHandleUtil.GetRequiredInstanceAttribute(ifcCurve, "BasisCurve", true); IFCCurve ifcBasisCurve = IFCCurve.ProcessIFCCurve(basisCurve); if (ifcBasisCurve == null || (ifcBasisCurve.Curve == null && ifcBasisCurve.CurveLoop == null)) { // LOG: ERROR: Error processing BasisCurve # for IfcTrimmedCurve #. return; } if (ifcBasisCurve.Curve == null) { // LOG: ERROR: Expected a single curve, not a curve loop for BasisCurve # for IfcTrimmedCurve #. return; } IFCData trim1 = ifcCurve.GetAttribute("Trim1"); if (trim1.PrimitiveType != IFCDataPrimitiveType.Aggregate) { // LOG: ERROR: Invalid data type for Trim1 attribute for IfcTrimmedCurve #. return; } IFCData trim2 = ifcCurve.GetAttribute("Trim2"); if (trim2.PrimitiveType != IFCDataPrimitiveType.Aggregate) { // LOG: ERROR: Invalid data type for Trim1 attribute for IfcTrimmedCurve #. return; } IFCTrimmingPreference trimPreference = IFCEnums.GetSafeEnumerationAttribute<IFCTrimmingPreference>(ifcCurve, "MasterRepresentation", IFCTrimmingPreference.Parameter); double param1 = 0.0, param2 = 0.0; try { GetTrimParameters(trim1, trim2, ifcBasisCurve, trimPreference, out param1, out param2); } catch (Exception ex) { Importer.TheLog.LogError(ifcCurve.StepId, ex.Message, false); return; } Curve baseCurve = ifcBasisCurve.Curve; if (baseCurve.IsCyclic) { if (!sameSense) MathUtil.Swap(ref param1, ref param2); if (param2 < param1) param2 = MathUtil.PutInRange(param2, param1 + Math.PI, 2 * Math.PI); if (param2 - param1 > 2.0 * Math.PI - MathUtil.Eps()) { Importer.TheLog.LogWarning(ifcCurve.StepId, "IfcTrimmedCurve length is greater than 2*PI, leaving unbound.", false); Curve = baseCurve; return; } Curve = baseCurve.Clone(); try { Curve.MakeBound(param1, param2); } catch (Exception ex) { if (ex.Message.Contains("too small")) { Curve = null; Importer.TheLog.LogError(Id, "curve length is invalid, ignoring.", false); return; } else throw ex; } } else { if (MathUtil.IsAlmostEqual(param1, param2)) { Importer.TheLog.LogError(Id, "Param1 = Param2 for IfcTrimmedCurve #, ignoring.", false); return; } if (param1 > param2 - MathUtil.Eps()) { Importer.TheLog.LogWarning(Id, "Param1 > Param2 for IfcTrimmedCurve #, reversing.", false); MathUtil.Swap(ref param1, ref param2); return; } Curve copyCurve = baseCurve.Clone(); double length = param2 - param1; if (length <= IFCImportFile.TheFile.Document.Application.ShortCurveTolerance) { string lengthAsString = IFCUnitUtil.FormatLengthAsString(length); Importer.TheLog.LogError(Id, "curve length of " + lengthAsString + " is invalid, ignoring.", false); return; } copyCurve.MakeBound(param1, param2); if (sameSense) { Curve = copyCurve; } else { Curve = copyCurve.CreateReversed(); } } CurveLoop = new CurveLoop(); CurveLoop.Append(Curve); }
/// <summary> /// Processes measure with unit. /// </summary> /// <param name="measureUnitHnd">The measure unit handle.</param> void ProcessIFCMeasureWithUnit(IFCAnyHandle measureUnitHnd) { double baseScale = 0.0; IFCData ifcData = measureUnitHnd.GetAttribute("ValueComponent"); if (!ifcData.HasValue) throw new InvalidOperationException("#" + measureUnitHnd.StepId + ": Missing required attribute ValueComponent."); if (ifcData.PrimitiveType == IFCDataPrimitiveType.Double) baseScale = ifcData.AsDouble(); else if (ifcData.PrimitiveType == IFCDataPrimitiveType.Integer) baseScale = (double)ifcData.AsInteger(); if (MathUtil.IsAlmostZero(baseScale)) throw new InvalidOperationException("#" + measureUnitHnd.StepId + ": ValueComponent should not be almost zero."); IFCAnyHandle unitHnd = IFCImportHandleUtil.GetRequiredInstanceAttribute(measureUnitHnd, "UnitComponent", true); IFCUnit unit = ProcessIFCUnit(unitHnd); CopyUnit(unit); ScaleFactor = unit.ScaleFactor * baseScale; }
/// <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; }
/// <summary> /// Processes an IFC property reference value. /// </summary> /// <param name="propertyReferenceValue">The IfcPropertyReferenceValue object.</param> void ProcessIFCPropertyReferenceValue(IFCAnyHandle propertyReferenceValue) { IFCData referenceValue = propertyReferenceValue.GetAttribute("PropertyReference"); IFCPropertyValues.Add(new IFCPropertyValue(this, referenceValue)); }
/// <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> /// Processes an IFC property single value. /// </summary> /// <param name="propertySingleValue">The IfcPropertySingleValue object.</param> void ProcessIFCPropertySingleValue(IFCAnyHandle propertySingleValue) { IFCPropertyValues.Add(new IFCPropertyValue(this, propertySingleValue.GetAttribute("NominalValue"))); ProcessIFCSimplePropertyUnit(this, propertySingleValue); }
private void ProcessIFCTrimmedCurve(IFCAnyHandle ifcCurve) { bool found = false; bool sameSense = IFCImportHandleUtil.GetRequiredBooleanAttribute(ifcCurve, "SenseAgreement", out found); if (!found) sameSense = true; IFCAnyHandle basisCurve = IFCImportHandleUtil.GetRequiredInstanceAttribute(ifcCurve, "BasisCurve", true); IFCCurve ifcBasisCurve = IFCCurve.ProcessIFCCurve(basisCurve); if (ifcBasisCurve == null || (ifcBasisCurve.Curve == null && ifcBasisCurve.CurveLoop == null)) { // LOG: ERROR: Error processing BasisCurve # for IfcTrimmedCurve #. return; } if (ifcBasisCurve.Curve == null) { // LOG: ERROR: Expected a single curve, not a curve loop for BasisCurve # for IfcTrimmedCurve #. return; } IFCData trim1 = ifcCurve.GetAttribute("Trim1"); if (trim1.PrimitiveType != IFCDataPrimitiveType.Aggregate) { // LOG: ERROR: Invalid data type for Trim1 attribute for IfcTrimmedCurve #. return; } IFCData trim2 = ifcCurve.GetAttribute("Trim2"); if (trim2.PrimitiveType != IFCDataPrimitiveType.Aggregate) { // LOG: ERROR: Invalid data type for Trim1 attribute for IfcTrimmedCurve #. return; } string trimPreferenceAsString = IFCAnyHandleUtil.GetEnumerationAttribute(ifcCurve, "MasterRepresentation"); IFCTrimmingPreference trimPreference = IFCTrimmingPreference.Parameter; if (trimPreferenceAsString != null) trimPreference = (IFCTrimmingPreference)Enum.Parse(typeof(IFCTrimmingPreference), trimPreferenceAsString, true); double param1 = 0.0, param2 = 0.0; try { GetTrimParameters(trim1, trim2, ifcBasisCurve, trimPreference, out param1, out param2); } catch (Exception ex) { IFCImportFile.TheLog.LogError(ifcCurve.StepId, ex.Message, false); return; } Curve baseCurve = ifcBasisCurve.Curve; if (baseCurve.IsCyclic) { if (!sameSense) MathUtil.Swap(ref param1, ref param2); if (param2 < param1) param2 = MathUtil.PutInRange(param2, param1 + Math.PI, 2 * Math.PI); if (param2 - param1 > 2.0 * Math.PI - MathUtil.Eps()) { // LOG: WARNING: #Id: IfcTrimmedCurve length is greater than 2*PI, leaving unbound. Curve = baseCurve; return; } Curve = baseCurve.Clone(); Curve.MakeBound(param1, param2); } else { if (MathUtil.IsAlmostEqual(param1, param2)) { // LOG: ERROR: Param1 = Param2 for IfcTrimmedCurve #, ignoring. return; } if (param1 > param2 - MathUtil.Eps()) { // LOG: WARNING: Param1 > Param2 for IfcTrimmedCurve #, reversing. MathUtil.Swap(ref param1, ref param2); return; } Curve copyCurve = baseCurve.Clone(); copyCurve.MakeBound(param1, param2); if (sameSense) { Curve = copyCurve; } else { Curve = copyCurve.CreateReversed(); } } }
private void ProcessIFCTrimmedCurve(IFCAnyHandle ifcCurve) { bool found = false; bool sameSense = IFCImportHandleUtil.GetRequiredBooleanAttribute(ifcCurve, "SenseAgreement", out found); if (!found) { sameSense = true; } IFCAnyHandle basisCurve = IFCImportHandleUtil.GetRequiredInstanceAttribute(ifcCurve, "BasisCurve", true); IFCCurve ifcBasisCurve = IFCCurve.ProcessIFCCurve(basisCurve); if (ifcBasisCurve == null || (ifcBasisCurve.Curve == null && ifcBasisCurve.CurveLoop == null)) { // LOG: ERROR: Error processing BasisCurve # for IfcTrimmedCurve #. return; } if (ifcBasisCurve.Curve == null) { // LOG: ERROR: Expected a single curve, not a curve loop for BasisCurve # for IfcTrimmedCurve #. return; } IFCData trim1 = ifcCurve.GetAttribute("Trim1"); if (trim1.PrimitiveType != IFCDataPrimitiveType.Aggregate) { // LOG: ERROR: Invalid data type for Trim1 attribute for IfcTrimmedCurve #. return; } IFCData trim2 = ifcCurve.GetAttribute("Trim2"); if (trim2.PrimitiveType != IFCDataPrimitiveType.Aggregate) { // LOG: ERROR: Invalid data type for Trim1 attribute for IfcTrimmedCurve #. return; } string trimPreferenceAsString = IFCAnyHandleUtil.GetEnumerationAttribute(ifcCurve, "MasterRepresentation"); IFCTrimmingPreference trimPreference = IFCTrimmingPreference.Parameter; if (trimPreferenceAsString != null) { trimPreference = (IFCTrimmingPreference)Enum.Parse(typeof(IFCTrimmingPreference), trimPreferenceAsString, true); } double param1 = 0.0, param2 = 0.0; try { GetTrimParameters(trim1, trim2, ifcBasisCurve, trimPreference, out param1, out param2); } catch (Exception ex) { IFCImportFile.TheLog.LogError(ifcCurve.StepId, ex.Message, false); return; } Curve baseCurve = ifcBasisCurve.Curve; if (baseCurve.IsCyclic) { if (!sameSense) { MathUtil.Swap(ref param1, ref param2); } if (param2 < param1) { param2 = MathUtil.PutInRange(param2, param1 + Math.PI, 2 * Math.PI); } if (param2 - param1 > 2.0 * Math.PI - MathUtil.Eps()) { // LOG: WARNING: #Id: IfcTrimmedCurve length is greater than 2*PI, leaving unbound. Curve = baseCurve; return; } Curve = baseCurve.Clone(); Curve.MakeBound(param1, param2); } else { if (MathUtil.IsAlmostEqual(param1, param2)) { // LOG: ERROR: Param1 = Param2 for IfcTrimmedCurve #, ignoring. return; } if (param1 > param2 - MathUtil.Eps()) { // LOG: WARNING: Param1 > Param2 for IfcTrimmedCurve #, reversing. MathUtil.Swap(ref param1, ref param2); return; } Curve copyCurve = baseCurve.Clone(); copyCurve.MakeBound(param1, param2); if (sameSense) { Curve = copyCurve; } else { Curve = copyCurve.CreateReversed(); } } }
/// <summary> /// Create association (IfcRelAssociatesClassification) between the Element (ElemHnd) and specified classification reference /// </summary> /// <param name="exporterIFC">The exporterIFC class.</param> /// <param name="file">The IFC file class.</param> /// <param name="elemHnd">The corresponding IFC entity handle.</param> /// <param name="classificationReference">The classification reference to be associated with</param> public static void AssociateClassificationReference(ExporterIFC exporterIFC, IFCFile file, IFCAnyHandle elemHnd, IFCAnyHandle classificationReference) { HashSet<IFCAnyHandle> relatedObjects = new HashSet<IFCAnyHandle>(); relatedObjects.Add(elemHnd); IFCAnyHandle relAssociates = IFCInstanceExporter.CreateRelAssociatesClassification(file, GUIDUtil.CreateGUID(), exporterIFC.GetOwnerHistoryHandle(), classificationReference.GetAttribute("ReferencedSource").ToString() + " Classification", "", relatedObjects, classificationReference); }