/// <summary> /// Create an electrical voltage measure property from the element's or type's parameter. /// </summary> /// <param name="file">The IFC file.</param> /// <param name="elem">The Element.</param> /// <param name="revitParameterName">The name of the parameter.</param> /// <param name="ifcPropertyName">The name of the property.</param> /// <param name="valueType">The value type of the property.</param> /// <returns>The created property handle.</returns> public static IFCAnyHandle CreateElectricalVoltageMeasurePropertyFromElementOrSymbol(IFCFile file, Element elem, string revitParameterName, string ifcPropertyName, PropertyValueType valueType) { double propertyValue; if (ParameterUtil.GetDoubleValueFromElement(elem, null, revitParameterName, out propertyValue) != null) { double scale = 0.3048; propertyValue *= scale * scale; return(CreateElectricalVoltageMeasurePropertyFromCache(file, ifcPropertyName, propertyValue, valueType)); } // For Symbol Document document = elem.Document; ElementId typeId = elem.GetTypeId(); Element elemType = document.GetElement(typeId); if (elemType != null) { return(CreateElectricalVoltageMeasurePropertyFromElementOrSymbol(file, elemType, revitParameterName, ifcPropertyName, valueType)); } else { return(null); } }
/// <summary> /// Creates IfcPresentationStyleAssignment for text element type. /// </summary> /// <param name="exporterIFC"> /// The ExporterIFC object. /// </param> /// <param name="textElemType"> /// The text note element type. /// </param> /// <param name="cache"> /// The cache of IfcPresentationStyleAssignment. /// </param> static void CreatePresentationStyleAssignmentForTextElementType(ExporterIFC exporterIFC, TextElementType textElemType, PresentationStyleAssignmentCache cache) { IFCFile file = exporterIFC.GetFile(); string fontName; if (ParameterUtil.GetStringValueFromElement(textElemType, BuiltInParameter.TEXT_FONT, out fontName) == null) { fontName = null; } double fontSize; if (ParameterUtil.GetDoubleValueFromElement(textElemType, BuiltInParameter.TEXT_SIZE, out fontSize) == null) { fontSize = -1.0; } double viewScale = 100.0; // currently hardwired. fontSize = UnitUtil.ScaleLength(fontSize * viewScale); string ifcPreDefinedItemName = "Text Font"; IList <string> fontNameList = new List <string>(); fontNameList.Add(fontName); IFCAnyHandle textSyleFontModelHnd = IFCInstanceExporter.CreateTextStyleFontModel(file, ifcPreDefinedItemName, fontNameList, null, null, null, IFCDataUtil.CreateAsPositiveLengthMeasure(fontSize)); int color; ParameterUtil.GetIntValueFromElement(textElemType, BuiltInParameter.LINE_COLOR, out color); double blueVal = ((double)((color & 0xff0000) >> 16)) / 255.0; double greenVal = ((double)((color & 0xff00) >> 8)) / 255.0; double redVal = ((double)(color & 0xff)) / 255.0; IFCAnyHandle colorHnd = IFCInstanceExporter.CreateColourRgb(file, null, redVal, greenVal, blueVal); IFCAnyHandle fontColorHnd = IFCInstanceExporter.CreateTextStyleForDefinedFont(file, colorHnd, null); string ifcAttrName = textElemType.Name; IFCAnyHandle textStyleHnd = IFCInstanceExporter.CreateTextStyle(file, textElemType.Name, fontColorHnd, null, textSyleFontModelHnd); if (IFCAnyHandleUtil.IsNullOrHasNoValue(textStyleHnd)) { return; } HashSet <IFCAnyHandle> presStyleSet = new HashSet <IFCAnyHandle>(); presStyleSet.Add(textStyleHnd); IFCAnyHandle presStyleHnd = IFCInstanceExporter.CreatePresentationStyleAssignment(file, presStyleSet); if (IFCAnyHandleUtil.IsNullOrHasNoValue(presStyleHnd)) { return; } cache.Register(textElemType.Id, presStyleHnd); }
/// <summary> /// Calculates slope value. /// </summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="extrusionCreationData">The IFCExtrusionCreationData.</param> /// <param name="element">The element to calculate the value.</param> /// <param name="elementType">The element type.</param> /// <returns>True if the operation succeed, false otherwise.</returns> public override bool Calculate(ExporterIFC exporterIFC, IFCExtrusionCreationData extrusionCreationData, Element element, ElementType elementType) { double slope = double.NaN; // We may have an extrusionCreationData that doesn't have anything set. We will check this by seeing if there is a valid length set. // This works for Beam if (extrusionCreationData == null || MathUtil.IsAlmostZero(extrusionCreationData.ScaledLength)) { // Try looking for parameters that we can calculate slope from. double startParamHeight = 0.0; double endParamHeight = 0.0; double length = 0.0; if ((ParameterUtil.GetDoubleValueFromElement(element, BuiltInParameter.STRUCTURAL_BEAM_END0_ELEVATION, out startParamHeight) != null) && (ParameterUtil.GetDoubleValueFromElement(element, BuiltInParameter.STRUCTURAL_BEAM_END1_ELEVATION, out endParamHeight) != null) && (ParameterUtil.GetDoubleValueFromElement(element, BuiltInParameter.INSTANCE_LENGTH_PARAM, out length) != null)) { if (!MathUtil.IsAlmostZero(length)) { double factor = Math.Abs(endParamHeight - startParamHeight) / length; slope = UnitUtil.ScaleAngle(MathUtil.SafeAsin(factor)); if (!double.IsNaN(slope)) { m_Slope = slope; return(true); } } } } // This works for Ramp/RampFlight if (ParameterUtil.GetDoubleValueFromElement(element, BuiltInParameter.RAMP_ATTR_MIN_INV_SLOPE, out slope) != null) { m_Slope = UnitUtil.ScaleAngle(Math.Atan(slope)); return(true); } // For other elements with ExtrusionData. Parameter will take precedence (override) if (ParameterUtil.GetDoubleValueFromElementOrSymbol(element, "Slope", out slope) != null) { m_Slope = UnitUtil.ScaleAngle(slope); return(true); } if (extrusionCreationData != null) { if (extrusionCreationData.Slope > MathUtil.Eps()) { m_Slope = extrusionCreationData.Slope; return(true); } else { // For any element that has axis, the slope will be computed based on the angle of the line vector if (element.Location != null && element.Location is LocationCurve) { LocationCurve axis = element.Location as LocationCurve; if (axis.Curve is Line) { Line axisCurve = axis.Curve as Line; XYZ vectorProjOnXY = new XYZ(axisCurve.Direction.X, axisCurve.Direction.Y, 0.0).Normalize(); //Project the vector to XY plane if (axisCurve.Direction.GetLength() > 0.0 && vectorProjOnXY.GetLength() > 0.0) { slope = UnitUtil.ScaleAngle(MathUtil.SafeAcos(axisCurve.Direction.DotProduct(vectorProjOnXY) / (axisCurve.Direction.GetLength() * vectorProjOnXY.GetLength()))); } if (!double.IsNaN(slope)) { m_Slope = slope; return(true); } } } } } // The last attempt to compute the slope angle is to get the slope of the largest top facing face of the geometry GeometryElement geomElem = element.get_Geometry(GeometryUtil.GetIFCExportGeometryOptions()); Face largestTopFace = null; if (geomElem == null) { return(false); } foreach (GeometryObject geomObj in geomElem) { largestTopFace = GeometryUtil.GetLargestFaceInSolid(geomObj, new XYZ(0, 0, 1)); } if (largestTopFace != null) { XYZ faceNormal = largestTopFace.ComputeNormal(new UV()); XYZ faceNormalProjXYPlane = new XYZ(faceNormal.X, faceNormal.Y, 0.0).Normalize(); slope = GeometryUtil.GetAngleOfFace(largestTopFace, faceNormalProjXYPlane); if (!double.IsNaN(slope)) { m_Slope = slope; return(true); } } return(false); }
/// <summary> /// Calculates slope value. /// </summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="extrusionCreationData">The IFCExtrusionCreationData.</param> /// <param name="element">The element to calculate the value.</param> /// <param name="elementType">The element type.</param> /// <returns>True if the operation succeed, false otherwise.</returns> public override bool Calculate(ExporterIFC exporterIFC, IFCExtrusionCreationData extrusionCreationData, Element element, ElementType elementType) { // We may have an extrusionCreationData that doesn't have anything set. We will check this by seeing if there is a valid length set. // This works for Beam if (extrusionCreationData == null || MathUtil.IsAlmostZero(extrusionCreationData.ScaledLength)) { // Try looking for parameters that we can calculate slope from. double startParamHeight = 0.0; double endParamHeight = 0.0; double length = 0.0; if ((ParameterUtil.GetDoubleValueFromElement(element, BuiltInParameter.STRUCTURAL_BEAM_END0_ELEVATION, out startParamHeight) != null) && (ParameterUtil.GetDoubleValueFromElement(element, BuiltInParameter.STRUCTURAL_BEAM_END1_ELEVATION, out endParamHeight) != null) && (ParameterUtil.GetDoubleValueFromElement(element, BuiltInParameter.INSTANCE_LENGTH_PARAM, out length) != null)) { if (!MathUtil.IsAlmostZero(length)) { double factor = Math.Abs(endParamHeight - startParamHeight) / length; double tempSlope = UnitUtil.ScaleAngle(MathUtil.SafeAsin(factor)); if (!Double.IsNaN(tempSlope)) { m_Slope = tempSlope; return(true); } } } } // This works for Ramp/RampFlight double slope = 0.0; if (ParameterUtil.GetDoubleValueFromElement(element, BuiltInParameter.RAMP_ATTR_MIN_INV_SLOPE, out slope) != null) { m_Slope = slope; if (!MathUtil.IsAlmostZero(m_Slope)) { m_Slope = UnitUtil.ScaleAngle(Math.Atan(m_Slope)); return(true); } } // For other elements with ExtrusionData. Parameter will take precedence (override) if (ParameterUtil.GetDoubleValueFromElementOrSymbol(element, "IfcSlope", out m_Slope) == null) { ParameterUtil.GetDoubleValueFromElementOrSymbol(element, "Slope", out m_Slope); } m_Slope = UnitUtil.ScaleAngle(m_Slope); if (m_Slope > MathUtil.Eps()) { return(true); } if (extrusionCreationData != null) { m_Slope = extrusionCreationData.Slope; return(true); } // The last attempt to compute the slope angle is to get the slope of the largest top facing face of the geometry GeometryElement geomElem = element.get_Geometry(GeometryUtil.GetIFCExportGeometryOptions()); Face largestTopFace = null; double largestArea = 0.0; foreach (GeometryObject geomObj in geomElem) { if (geomObj is Solid) { Solid geomSolid = geomObj as Solid; foreach (Face face in geomSolid.Faces) { if (!(face is PlanarFace)) { continue; } // Identifying the largest area with normal pointing up if (face.Area > largestArea && face.ComputeNormal(new UV()).Z > 0) { largestTopFace = face; largestArea = face.Area; } } } } if (largestTopFace != null) { XYZ faceNormal = largestTopFace.ComputeNormal(new UV()); XYZ faceNormalProjXYPlane = new XYZ(faceNormal.X, faceNormal.Y, 0.0).Normalize(); double normalAngleToXYPlane = Math.Acos(faceNormal.DotProduct(faceNormalProjXYPlane)); double slopeAngle = 0.5 * Math.PI - normalAngleToXYPlane; m_Slope = UnitUtil.ScaleAngle(slopeAngle); return(true); } return(false); }
/// <summary> /// Calculates number of risers for a stair. /// </summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="extrusionCreationData">The IFCExtrusionCreationData.</param> /// <param name="element">The element to calculate the value.</param> /// <param name="elementType">The element type.</param> /// <returns>True if the operation succeed, false otherwise.</returns> public override bool Calculate(ExporterIFC exporterIFC, IFCExtrusionCreationData extrusionCreationData, Element element, ElementType elementType) { bool valid = true; if (CurrentElement != element) { CurrentElement = element; if (StairsExporter.IsLegacyStairs(element)) { int numberOfRisers, numberOfTreads; double riserHeight, treadLength, treadLengthAtInnerSide, nosingLength, waistThickness; ExporterIFCUtils.GetLegacyStairsProperties(exporterIFC, element, out numberOfRisers, out numberOfTreads, out riserHeight, out treadLength, out treadLengthAtInnerSide, out nosingLength, out waistThickness); NumberOfRisers = numberOfRisers; NumberOfTreads = numberOfTreads; RiserHeight = riserHeight; TreadLength = treadLength; TreadLengthAtInnerSide = treadLengthAtInnerSide; NosingLength = nosingLength; WaistThickness = waistThickness; TreadLengthAtOffset = TreadLength; WalkingLineOffset = WaistThickness / 2.0; } else if (element is Stairs) { Stairs stairs = element as Stairs; NumberOfRisers = stairs.ActualRisersNumber; NumberOfTreads = stairs.ActualTreadsNumber; RiserHeight = UnitUtil.ScaleLength(stairs.ActualRiserHeight); TreadLength = UnitUtil.ScaleLength(stairs.ActualTreadDepth); } else if (element is StairsRun) { StairsRun stairsRun = element as StairsRun; StairsRunType stairsRunType = stairsRun.Document.GetElement(stairsRun.GetTypeId()) as StairsRunType; Stairs stairs = stairsRun.GetStairs(); StairsType stairsType = stairs.Document.GetElement(stairs.GetTypeId()) as StairsType; NumberOfRisers = stairs.ActualRisersNumber; NumberOfTreads = stairs.ActualTreadsNumber; RiserHeight = UnitUtil.ScaleLength(stairs.ActualRiserHeight); TreadLength = UnitUtil.ScaleLength(stairs.ActualTreadDepth); TreadLengthAtOffset = TreadLength; NosingLength = UnitUtil.ScaleLength(stairsRunType.NosingLength); WaistThickness = UnitUtil.ScaleLength(stairsRun.ActualRunWidth); WalkingLineOffset = WaistThickness / 2.0; double treadLengthAtInnerSide; if (ParameterUtil.GetDoubleValueFromElement(stairsType, BuiltInParameter.STAIRSTYPE_MINIMUM_TREAD_WIDTH_INSIDE_BOUNDARY, out treadLengthAtInnerSide) != null) { TreadLengthAtInnerSide = UnitUtil.ScaleLength(treadLengthAtInnerSide); } else { TreadLengthAtInnerSide = 0.0; } } else { valid = false; } } return(valid); }
/// <summary> /// Calculates cross area. /// </summary> /// <param name="exporterIFC"> /// The ExporterIFC object. /// </param> /// <param name="extrusionCreationData"> /// The IFCExtrusionCreationData. /// </param> /// <param name="element"> /// The element to calculate the value. /// </param> /// <param name="elementType"> /// The element type. /// </param> /// <returns> /// True if the operation succeed, false otherwise. /// </returns> public override bool Calculate(ExporterIFC exporterIFC, IFCExtrusionCreationData extrusionCreationData, Element element, ElementType elementType, EntryMap entryMap) { double lengthFromParam = 0; if (ParameterUtil.GetDoubleValueFromElementOrSymbol(element, entryMap.RevitParameterName, out lengthFromParam) == null) { if (ParameterUtil.GetDoubleValueFromElementOrSymbol(element, entryMap.CompatibleRevitParameterName, out lengthFromParam) == null) { ParameterUtil.GetDoubleValueFromElementOrSymbol(element, "IfcQtyLength", out lengthFromParam); } } m_Length = UnitUtil.ScaleLength(lengthFromParam); // Check for Stair Run - Do special computation for the length if (element is StairsRun) { StairsRun flight = element as StairsRun; double flightLen = flight.GetStairsPath().GetExactLength(); flightLen = UnitUtil.ScaleLength(flightLen); if (flightLen > MathUtil.Eps()) { m_Length = flightLen; return(true); } // consider override as specified in a parameter else if (m_Length > MathUtil.Eps()) { return(true); } // exit when none for StairsRun else { return(false); } } // For others if (m_Length > MathUtil.Eps()) { return(true); } if (extrusionCreationData == null) { if (ParameterUtil.GetDoubleValueFromElement(element, BuiltInParameter.EXTRUSION_LENGTH, out m_Length) != null) { m_Length = UnitUtil.ScaleLength(m_Length); } } else { // For Slab, length is the major edge of the rectangle area profile (get it from ScaledWidth) // Also for Stair support IFCAnyHandle hnd = ExporterCacheManager.ElementToHandleCache.Find(element.Id); if (IFCAnyHandleUtil.IsSubTypeOf(hnd, IFCEntityType.IfcSlab) || element.Category.BuiltInCategory == BuiltInCategory.OST_StairsStringerCarriage) { m_Length = extrusionCreationData.ScaledWidth; } else { m_Length = extrusionCreationData.ScaledLength; } } if (m_Length > MathUtil.Eps()) { return(true); } return(false); }
/// <summary> /// Calculates slope value. /// </summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="extrusionCreationData">The IFCExtrusionCreationData.</param> /// <param name="element">The element to calculate the value.</param> /// <param name="elementType">The element type.</param> /// <returns>True if the operation succeed, false otherwise.</returns> public override bool Calculate(ExporterIFC exporterIFC, IFCExtrusionCreationData extrusionCreationData, Element element, ElementType elementType) { // We may have an extrusionCreationData that doesn't have anything set. We will check this by seeing if there is a valid length set. // This works for Beam if (extrusionCreationData == null || MathUtil.IsAlmostZero(extrusionCreationData.ScaledLength)) { // Try looking for parameters that we can calculate slope from. double startParamHeight = 0.0; double endParamHeight = 0.0; double length = 0.0; if ((ParameterUtil.GetDoubleValueFromElement(element, BuiltInParameter.STRUCTURAL_BEAM_END0_ELEVATION, out startParamHeight) != null) && (ParameterUtil.GetDoubleValueFromElement(element, BuiltInParameter.STRUCTURAL_BEAM_END1_ELEVATION, out endParamHeight) != null) && (ParameterUtil.GetDoubleValueFromElement(element, BuiltInParameter.INSTANCE_LENGTH_PARAM, out length) != null)) { if (!MathUtil.IsAlmostZero(length)) { double factor = Math.Abs(endParamHeight - startParamHeight) / length; double tempSlope = UnitUtil.ScaleAngle(MathUtil.SafeAsin(factor)); if (!Double.IsNaN(tempSlope)) { m_Slope = tempSlope; return(true); } } } } // This works for Ramp/RampFlight double slope = 0.0; if (ParameterUtil.GetDoubleValueFromElement(element, BuiltInParameter.RAMP_ATTR_MIN_INV_SLOPE, out slope) != null) { m_Slope = slope; if (!MathUtil.IsAlmostZero(m_Slope)) { m_Slope = UnitUtil.ScaleAngle(Math.Atan(m_Slope)); return(true); } } // For other elements with ExtrusionData. Parameter will take precedence (override) if (ParameterUtil.GetDoubleValueFromElementOrSymbol(element, "IfcSlope", out m_Slope) == null) { ParameterUtil.GetDoubleValueFromElementOrSymbol(element, "Slope", out m_Slope); } m_Slope = UnitUtil.ScaleAngle(m_Slope); if (m_Slope > MathUtil.Eps()) { return(true); } if (extrusionCreationData != null) { m_Slope = extrusionCreationData.Slope; return(true); } return(false); }
/// <summary> /// Calculates cross area. /// </summary> /// <param name="exporterIFC"> /// The ExporterIFC object. /// </param> /// <param name="extrusionCreationData"> /// The IFCExtrusionCreationData. /// </param> /// <param name="element"> /// The element to calculate the value. /// </param> /// <param name="elementType"> /// The element type. /// </param> /// <returns> /// True if the operation succeed, false otherwise. /// </returns> public override bool Calculate(ExporterIFC exporterIFC, IFCExtrusionCreationData extrusionCreationData, Element element, ElementType elementType) { double lengthFromParam = 0; if (ParameterUtil.GetDoubleValueFromElementOrSymbol(element, "IfcQtyLength", out lengthFromParam) == null) { if (ParameterUtil.GetDoubleValueFromElementOrSymbol(element, "IfcLength", out lengthFromParam) == null) { ParameterUtil.GetDoubleValueFromElementOrSymbol(element, "Length", out lengthFromParam); } } m_Length = UnitUtil.ScaleLength(lengthFromParam); // Check for Stair Run - Do special computation for the length if (element is StairsRun) { StairsRun flight = element as StairsRun; double flightLen = flight.GetStairsPath().GetExactLength(); flightLen = UnitUtil.ScaleLength(flightLen); if (flightLen > MathUtil.Eps()) { m_Length = flightLen; return(true); } // consider override as specified in a parameter else if (m_Length > MathUtil.Eps()) { return(true); } // exit when none for StairsRun else { return(false); } } // For others if (m_Length > MathUtil.Eps()) { return(true); } if (extrusionCreationData == null) { if (ParameterUtil.GetDoubleValueFromElement(element, BuiltInParameter.EXTRUSION_LENGTH, out m_Length) != null) { m_Length = UnitUtil.ScaleLength(m_Length); } } else { m_Length = extrusionCreationData.ScaledLength; } if (m_Length > MathUtil.Eps()) { return(true); } return(false); }