Beispiel #1
0
        /// <summary>
        /// Creates the 3D and 2D contexts information.
        /// </summary>
        /// <param name="exporterIFC">The IFC exporter object.</param>
        /// <param name="doc">The document provides the ProjectLocation.</param>
        /// <returns>The collection contains the 3D/2D context (not sub-context) handles of IFC file.</returns>
        private HashSet<IFCAnyHandle> CreateContextInformation(ExporterIFC exporterIFC, Document doc)
        {
            HashSet<IFCAnyHandle> repContexts = new HashSet<IFCAnyHandle>();
            double scaledPrecision = UnitUtil.ScaleLength(doc.Application.VertexTolerance/10.0);
            int exponent = Convert.ToInt32(Math.Log10(scaledPrecision));
            double precision = Math.Pow(10.0, exponent);
            
            IFCFile file = exporterIFC.GetFile();
            IFCAnyHandle origin = ExporterIFCUtils.GetGlobal3DOriginHandle();
            IFCAnyHandle wcs = IFCInstanceExporter.CreateAxis2Placement3D(file, origin, null, null);

            double trueNorthAngleInRadians;
            ExporterUtil.GetSafeProjectPositionAngle(doc, out trueNorthAngleInRadians);

            // CoordinationView2.0 requires that we always export true north, even if it is the same as project north.
            IFCAnyHandle trueNorth = null;
            {
                double trueNorthAngleConverted = -trueNorthAngleInRadians + Math.PI / 2.0;
                List<double> dirRatios = new List<double>();
                dirRatios.Add(Math.Cos(trueNorthAngleConverted));
                dirRatios.Add(Math.Sin(trueNorthAngleConverted));
                trueNorth = IFCInstanceExporter.CreateDirection(file, dirRatios);
            }

            int dimCount = 3;
            IFCAnyHandle context3D = IFCInstanceExporter.CreateGeometricRepresentationContext(file, null,
                "Model", dimCount, precision, wcs, trueNorth);
            // CoordinationView2.0 requires sub-contexts of "Axis", "Body", and "Box".  We will use these for regular export also.
            {
                IFCAnyHandle context3DAxis = IFCInstanceExporter.CreateGeometricRepresentationSubContext(file,
                    "Axis", "Model", context3D, null, Toolkit.IFCGeometricProjection.Graph_View, null);
                IFCAnyHandle context3DBody = IFCInstanceExporter.CreateGeometricRepresentationSubContext(file,
                    "Body", "Model", context3D, null, Toolkit.IFCGeometricProjection.Model_View, null);
                IFCAnyHandle context3DBox = IFCInstanceExporter.CreateGeometricRepresentationSubContext(file,
                    "Box", "Model", context3D, null, Toolkit.IFCGeometricProjection.Model_View, null);
                IFCAnyHandle context3DFootPrint = IFCInstanceExporter.CreateGeometricRepresentationSubContext(file,
                    "FootPrint", "Model", context3D, null, Toolkit.IFCGeometricProjection.Model_View, null);

                exporterIFC.Set3DContextHandle(context3DAxis, "Axis");
                exporterIFC.Set3DContextHandle(context3DBody, "Body");
                exporterIFC.Set3DContextHandle(context3DBox, "Box");
                exporterIFC.Set3DContextHandle(context3DFootPrint, "FootPrint");
            }

            exporterIFC.Set3DContextHandle(context3D, "");
            repContexts.Add(context3D); // Only Contexts in list, not sub-contexts.

            if (ExporterCacheManager.ExportOptionsCache.ExportAnnotations)
            {
                string context2DType = "Annotation";
                IFCAnyHandle context2DHandle = IFCInstanceExporter.CreateGeometricRepresentationContext(file,
                    null, context2DType, dimCount, precision, wcs, trueNorth);

                IFCAnyHandle context2D = IFCInstanceExporter.CreateGeometricRepresentationSubContext(file,
                    null, context2DType, context2DHandle, 0.01, Toolkit.IFCGeometricProjection.Plan_View, null);

                exporterIFC.Set2DContextHandle(context2D);
                repContexts.Add(context2DHandle); // Only Contexts in list, not sub-contexts.
            }

            return repContexts;
        }
        /// <summary>
        /// Creates the 3D and 2D contexts information.
        /// </summary>
        /// <param name="exporterIFC">The IFC exporter object.</param>
        /// <param name="doc">The document provides the ProjectLocation.</param>
        /// <returns>The collection contains the 3D/2D context (not sub-context) handles of IFC file.</returns>
        private HashSet<IFCAnyHandle> CreateContextInformation(ExporterIFC exporterIFC, Document doc)
        {
            HashSet<IFCAnyHandle> repContexts = new HashSet<IFCAnyHandle>();
            double scale = exporterIFC.LinearScale;
            double precision = MathUtil.Eps();
            if (scale > 1.0 + precision)
            {
                int exponent = ((int)(Math.Log10(scale) - 0.01)) + 1;
                precision *= Math.Pow(10.0, exponent);
            }
            IFCFile file = exporterIFC.GetFile();
            IFCAnyHandle origin = ExporterIFCUtils.GetGlobal3DOriginHandle();
            IFCAnyHandle wcs = IFCInstanceExporter.CreateAxis2Placement3D(file, origin, null, null);

            ProjectLocation projLoc = doc.ActiveProjectLocation;
            double trueNorthAngleInRadians = 0.0;
            try
            {
                ProjectPosition projPos = projLoc.get_ProjectPosition(XYZ.Zero);
                trueNorthAngleInRadians = projPos.Angle;
            }
            catch (InternalException)
            {
                //fail to get true north, ignore
            }

            // CoordinationView2.0 requires that we always export true north, even if it is the same as project north.
            IFCAnyHandle trueNorth = null;
            {
                double trueNorthAngleConverted = -trueNorthAngleInRadians + Math.PI / 2.0;
                List<double> dirRatios = new List<double>();
                dirRatios.Add(2);
                dirRatios.Add(Math.Cos(trueNorthAngleConverted));
                dirRatios.Add(Math.Sin(trueNorthAngleConverted));
                trueNorth = IFCInstanceExporter.CreateDirection(file, dirRatios);
            }

            int dimCount = 3;
            IFCAnyHandle context3D = IFCInstanceExporter.CreateGeometricRepresentationContext(file, null,
                "Model", dimCount, precision, wcs, trueNorth);
            // CoordinationView2.0 requires sub-contexts of "Axis", "Body", and "Box".  We will use these for regular export also.
            {
                IFCAnyHandle context3DAxis = IFCInstanceExporter.CreateGeometricRepresentationSubContext(file,
                    "Axis", "Model", context3D, null, Toolkit.IFCGeometricProjection.Graph_View, null);
                IFCAnyHandle context3DBody = IFCInstanceExporter.CreateGeometricRepresentationSubContext(file,
                    "Body", "Model", context3D, null, Toolkit.IFCGeometricProjection.Model_View, null);
                IFCAnyHandle context3DBox = IFCInstanceExporter.CreateGeometricRepresentationSubContext(file,
                    "Box", "Model", context3D, null, Toolkit.IFCGeometricProjection.Model_View, null);
                IFCAnyHandle context3DFootPrint = IFCInstanceExporter.CreateGeometricRepresentationSubContext(file,
                    "FootPrint", "Model", context3D, null, Toolkit.IFCGeometricProjection.Model_View, null);

                exporterIFC.Set3DContextHandle(context3DAxis, "Axis");
                exporterIFC.Set3DContextHandle(context3DBody, "Body");
                exporterIFC.Set3DContextHandle(context3DBox, "Box");
                exporterIFC.Set3DContextHandle(context3DFootPrint, "FootPrint");
            }

            exporterIFC.Set3DContextHandle(context3D, "");
            repContexts.Add(context3D); // Only Contexts in list, not sub-contexts.

            if (ExporterCacheManager.ExportOptionsCache.ExportAnnotations)
            {
                string context2DType = "Annotation";
                IFCAnyHandle context2DHandle = IFCInstanceExporter.CreateGeometricRepresentationContext(file,
                    null, context2DType, dimCount, precision, wcs, trueNorth);

                IFCAnyHandle context2D = IFCInstanceExporter.CreateGeometricRepresentationSubContext(file,
                    null, context2DType, context2DHandle, 0.01, Toolkit.IFCGeometricProjection.Plan_View, null);

                exporterIFC.Set2DContextHandle(context2D);
                repContexts.Add(context2DHandle); // Only Contexts in list, not sub-contexts.
            }

            return repContexts;
        }