Ejemplo n.º 1
0
        /// <summary>
        /// Creates IfcDirection object.
        /// </summary>
        /// <param name="file">
        /// The IFC file.
        /// </param>
        /// <param name="realList">
        /// The list of doubles to create the direction.
        /// </param>
        /// <returns>
        /// The handle.
        /// </returns>
        public static IFCAnyHandle CreateDirection(IFCFile file, IList <double> realList)
        {
            IList <double> cleanList = new List <double>();

            foreach (double measure in realList)
            {
                double ceilMeasure  = Math.Ceiling(measure);
                double floorMeasure = Math.Floor(measure);

                if (MathUtil.IsAlmostEqual(measure, ceilMeasure))
                {
                    cleanList.Add(ceilMeasure);
                }
                else if (MathUtil.IsAlmostEqual(measure, floorMeasure))
                {
                    cleanList.Add(floorMeasure);
                }
                else
                {
                    cleanList.Add(measure);
                }
            }

            int sz = realList.Count;

            if (sz == 3)
            {
                for (int ii = 0; ii < 3; ii++)
                {
                    if (MathUtil.IsAlmostEqual(cleanList[ii], 1.0))
                    {
                        if (!MathUtil.IsAlmostZero(cleanList[(ii + 1) % 3]) || !MathUtil.IsAlmostZero(cleanList[(ii + 2) % 3]))
                        {
                            break;
                        }
                        return(ExporterIFCUtils.GetGlobal3DDirectionHandles(true)[ii]);
                    }
                    else if (MathUtil.IsAlmostEqual(cleanList[ii], -1.0))
                    {
                        if (!MathUtil.IsAlmostZero(cleanList[(ii + 1) % 3]) || !MathUtil.IsAlmostZero(cleanList[(ii + 2) % 3]))
                        {
                            break;
                        }
                        return(ExporterIFCUtils.GetGlobal3DDirectionHandles(false)[ii]);
                    }
                }
            }
            else if (sz == 2)
            {
                for (int ii = 0; ii < 2; ii++)
                {
                    if (MathUtil.IsAlmostEqual(cleanList[ii], 1.0))
                    {
                        if (!MathUtil.IsAlmostZero(cleanList[1 - ii]))
                        {
                            break;
                        }
                        return(ExporterIFCUtils.GetGlobal2DDirectionHandles(true)[ii]);
                    }
                    else if (MathUtil.IsAlmostEqual(cleanList[ii], -1.0))
                    {
                        if (!MathUtil.IsAlmostZero(cleanList[1 - ii]))
                        {
                            break;
                        }
                        return(ExporterIFCUtils.GetGlobal2DDirectionHandles(false)[ii]);
                    }
                }
            }

            IFCAnyHandle directionHandle = IFCInstanceExporter.CreateDirection(file, cleanList);

            return(directionHandle);
        }