// TODO: this function should be moved to IFCBoundingBox.cs now that they are fully supported.
        static private BoundingBoxXYZ ProcessBoundingBox(IFCAnyHandle boundingBoxHnd)
        {
            IFCAnyHandle lowerLeftHnd = IFCAnyHandleUtil.GetInstanceAttribute(boundingBoxHnd, "Corner");
            XYZ          minXYZ       = IFCPoint.ProcessScaledLengthIFCCartesianPoint(lowerLeftHnd);

            bool   found = false;
            double xDim  = IFCImportHandleUtil.GetRequiredScaledLengthAttribute(boundingBoxHnd, "XDim", out found);

            if (!found)
            {
                return(null);
            }

            double yDim = IFCImportHandleUtil.GetRequiredScaledLengthAttribute(boundingBoxHnd, "YDim", out found);

            if (!found)
            {
                return(null);
            }

            double zDim = IFCImportHandleUtil.GetRequiredScaledLengthAttribute(boundingBoxHnd, "ZDim", out found);

            if (!found)
            {
                return(null);
            }

            XYZ            maxXYZ      = new XYZ(minXYZ.X + xDim, minXYZ.Y + yDim, minXYZ.Z + zDim);
            BoundingBoxXYZ boundingBox = new BoundingBoxXYZ();

            boundingBox.set_Bounds(0, minXYZ);
            boundingBox.set_Bounds(1, maxXYZ);
            return(boundingBox);
        }
        public void SetCropBox(Document doc, ElevationMarker marker, Wall w)
        {
            ViewSection    extElev = (ViewSection)doc.GetElement(marker.GetViewId(0));
            BoundingBoxXYZ eecb    = extElev.CropBox;

            XYZ cbboundsmin = extElev.CropBox.Min;
            XYZ cbboundsmax = extElev.CropBox.Max;

            LocationCurve wallCurve = w.Location as LocationCurve;
            XYZ           wmin      = wallCurve.Curve.GetEndPoint(0);
            XYZ           wallEP2   = wallCurve.Curve.GetEndPoint(1);

            Parameter wallHeight = w.get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM);
            XYZ       wmax       = new XYZ
                                   (
                wallEP2.X,
                wallEP2.Y,
                wallEP2.Z + wallHeight.AsDouble()
                                   );

            double[][] transform    = Matrix.transform2matrix(eecb.Transform);
            double[][] transformInv = Matrix.invert(transform);

            double[] wMinMatrix  = Matrix.xyz2matrix(wmin);
            double[] wMinTMatrix = Matrix.dot(transform, wMinMatrix);
            XYZ      wMinT       = Matrix.matrix2xyz(wMinTMatrix);

            double[] wMaxMatrix  = Matrix.xyz2matrix(wmax);
            double[] wMaxTMatrix = Matrix.dot(transform, wMaxMatrix);
            XYZ      wMaxT       = Matrix.matrix2xyz(wMaxTMatrix);


            double[] originMatrix  = Matrix.xyz2matrix(eecb.Transform.Origin);
            double[] originTMatrix = Matrix.dot(transform, originMatrix);
            XYZ      originT       = Matrix.matrix2xyz(originTMatrix);

            XYZ wMinTOrdered;
            XYZ wMaxTOrdered;

            Utility.ReorderMinMax(wMinT, wMaxT, out wMinTOrdered, out wMaxTOrdered);

            XYZ wbbboundsmin = new XYZ(
                wMinTOrdered.X - originT.X,
                wMinTOrdered.Y - originT.Y,
                cbboundsmin.Z
                );
            XYZ wbbboundsmax = new XYZ(
                wMaxTOrdered.X - originT.X,
                wMaxTOrdered.Y - originT.Y - 0.01,
                cbboundsmax.Z
                );

            eecb.set_Bounds(0, wbbboundsmin);
            eecb.set_Bounds(1, wbbboundsmax);

            extElev.CropBox        = eecb;
            extElev.CropBoxVisible = false;
        }
        ////[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
        public static BoundingBoxXYZ ViewExtentsBoundingBox(UIView view)
        {
            if (view == null)
            {
                return(new BoundingBoxXYZ());
            }
            BoundingBoxXYZ result = new BoundingBoxXYZ();
            XYZ            min    = new XYZ(view.GetZoomCorners()[0].X, view.GetZoomCorners()[0].Y, view.GetZoomCorners()[0].Z - 4);
            XYZ            max    = new XYZ(view.GetZoomCorners()[1].X, view.GetZoomCorners()[1].Y, view.GetZoomCorners()[1].Z + 4);

            result.set_Bounds(0, min);
            result.set_Bounds(1, max);
            return(result);
        }
Esempio n. 4
0
        static private BoundingBoxXYZ ProcessBoundingBox(IFCAnyHandle boundingBoxHnd)
        {
            IFCAnyHandle lowerLeftHnd = IFCAnyHandleUtil.GetInstanceAttribute(boundingBoxHnd, "Corner");
            XYZ          minXYZ       = IFCPoint.ProcessScaledLengthIFCCartesianPoint(lowerLeftHnd);

            double xDim = IFCAnyHandleUtil.GetDoubleAttribute(boundingBoxHnd, "XDim").Value;
            double yDim = IFCAnyHandleUtil.GetDoubleAttribute(boundingBoxHnd, "YDim").Value;
            double zDim = IFCAnyHandleUtil.GetDoubleAttribute(boundingBoxHnd, "ZDim").Value;

            XYZ            maxXYZ      = new XYZ(minXYZ.X + xDim, minXYZ.Y + yDim, minXYZ.Z + zDim);
            BoundingBoxXYZ boundingBox = new BoundingBoxXYZ();

            boundingBox.set_Bounds(0, minXYZ);
            boundingBox.set_Bounds(1, maxXYZ);
            return(boundingBox);
        }
        ////[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
        public static BoundingBoxXYZ SectionViewExtentsBoundingBox(UIView view)
        {
            if (view == null)
            {
                return(new BoundingBoxXYZ());
            }
            BoundingBoxXYZ result = new BoundingBoxXYZ();

            try
            {
                XYZ min = new XYZ(view.GetZoomCorners()[0].X, view.GetZoomCorners()[0].Y, view.GetZoomCorners()[0].Z - 4);
                XYZ max = new XYZ(view.GetZoomCorners()[1].X, view.GetZoomCorners()[1].Y, view.GetZoomCorners()[1].Z + 4);
                result.set_Bounds(0, min);
                result.set_Bounds(1, max);
            }
            catch (ArgumentException ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                result.Dispose();
                return(null);
            }
            return(result);
        }
Esempio n. 6
0
        // Handles Solid, Mesh, and Face.
        private static BoundingBoxXYZ ComputeApproximateBoundingBox(IList<Solid> solids, IList<Mesh> polymeshes, IList<Face> independentFaces, Transform trf)
        {
            XYZ minBound = new XYZ(1000000000, 1000000000, 1000000000);
            XYZ maxBound = new XYZ(-1000000000, -1000000000, -1000000000);

            IList<Face> planarFaces = new List<Face>();
            IList<Face> nonPlanarFaces = new List<Face>();
            ICollection<Edge> edgesToTesselate = new HashSet<Edge>();

            foreach (Face face in independentFaces)
            {
                if (face is PlanarFace)
                    planarFaces.Add(face);
                else
                    nonPlanarFaces.Add(face);
            }

            foreach (Solid solid in solids)
            {
                FaceArray faces = solid.Faces;
                IList<Face> solidPlanarFaces = new List<Face>();
                foreach (Face face in faces)
                {
                    if (face is PlanarFace)
                        solidPlanarFaces.Add(face);
                    else
                        nonPlanarFaces.Add(face);
                }

                if (solidPlanarFaces.Count() == faces.Size)
                {
                    foreach (Edge edge in solid.Edges)
                        edgesToTesselate.Add(edge);
                }
                else
                {
                    foreach (Face planarFace in solidPlanarFaces)
                        planarFaces.Add(planarFace);
                }
            }

            foreach (Face planarFace in planarFaces)
            {
                EdgeArrayArray edgeLoops = planarFace.EdgeLoops;
                foreach (EdgeArray edgeLoop in edgeLoops)
                {
                    foreach (Edge edge in edgeLoop)
                        edgesToTesselate.Add(edge);
                }
            }

            foreach (Edge edge in edgesToTesselate)
            {
                IList<XYZ> edgeVertices = edge.Tessellate();
                IList<XYZ> transformedEdgeVertices = TransformVertexList(edgeVertices, trf);
                minBound = NewMinBound(minBound, transformedEdgeVertices);
                maxBound = NewMaxBound(maxBound, transformedEdgeVertices);
            }

            foreach (Face nonPlanarFace in nonPlanarFaces)
            {
                Mesh faceMesh = nonPlanarFace.Triangulate();
                polymeshes.Add(faceMesh);
            }

            foreach (Mesh mesh in polymeshes)
            {
                IList<XYZ> vertices = mesh.Vertices;
                IList<XYZ> transformedVertices = TransformVertexList(vertices, trf);
                minBound = NewMinBound(minBound, transformedVertices);
                maxBound = NewMaxBound(maxBound, transformedVertices);
            }

            BoundingBoxXYZ boundingBox = new BoundingBoxXYZ();
            boundingBox.set_Bounds(0, minBound);
            boundingBox.set_Bounds(1, maxBound);
            return boundingBox;
        }
Esempio n. 7
0
        private static BoundingBoxXYZ GetBoundingBox(List <Element> elements)
        {
            BoundingBoxXYZ boundingBox = new BoundingBoxXYZ();

            try
            {
                boundingBox.Enabled = true;
                for (int i = 0; i < 3; i++)
                {
                    boundingBox.set_MinEnabled(i, true);
                    boundingBox.set_MaxEnabled(i, true);
                    boundingBox.set_BoundEnabled(0, i, true);
                    boundingBox.set_BoundEnabled(1, i, true);
                }

                BoundingBoxXYZ tempBoundingBox = elements.First().get_BoundingBox(null);
                if (null != tempBoundingBox)
                {
                    tempBoundingBox.Enabled = true;

                    double maxX = tempBoundingBox.Max.X;
                    double maxY = tempBoundingBox.Max.Y;
                    double maxZ = tempBoundingBox.Max.Z;
                    double minX = tempBoundingBox.Min.X;
                    double minY = tempBoundingBox.Min.Y;
                    double minZ = tempBoundingBox.Min.Z;

                    foreach (Element element in elements)
                    {
                        try
                        {
                            BoundingBoxXYZ bbBox = element.get_BoundingBox(null);
                            if (null != boundingBox)
                            {
                                bbBox.Enabled = true;
                                if (bbBox.Max.X > maxX)
                                {
                                    maxX = bbBox.Max.X;
                                }
                                if (bbBox.Max.Y > maxY)
                                {
                                    maxY = bbBox.Max.Y;
                                }
                                if (bbBox.Max.Z > maxZ)
                                {
                                    maxZ = bbBox.Max.Z;
                                }
                                if (bbBox.Min.X < minX)
                                {
                                    minX = bbBox.Min.X;
                                }
                                if (bbBox.Min.Y < minY)
                                {
                                    minY = bbBox.Min.Y;
                                }
                                if (bbBox.Min.Z < minZ)
                                {
                                    minZ = bbBox.Min.Z;
                                }
                            }
                        }
                        catch
                        {
                            continue;
                        }
                    }

                    XYZ xyzMax = new XYZ(maxX, maxY, maxZ);
                    XYZ xyzMin = new XYZ(minX, minY, minZ);

                    boundingBox.set_Bounds(0, xyzMin);
                    boundingBox.set_Bounds(1, xyzMax);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to get bounding box XYZ.\n" + ex.Message, "Get Bounding Box", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            return(boundingBox);
        }
        // Handles Solid, Mesh, and Face.
        private static BoundingBoxXYZ ComputeApproximateBoundingBox(IList <Solid> solids, IList <Mesh> polymeshes, IList <Face> independentFaces, Transform trf)
        {
            XYZ minBound = new XYZ(1000000000, 1000000000, 1000000000);
            XYZ maxBound = new XYZ(-1000000000, -1000000000, -1000000000);

            IList <Face>       planarFaces      = new List <Face>();
            IList <Face>       nonPlanarFaces   = new List <Face>();
            ICollection <Edge> edgesToTesselate = new HashSet <Edge>();

            foreach (Face face in independentFaces)
            {
                if (face is PlanarFace)
                {
                    planarFaces.Add(face);
                }
                else
                {
                    nonPlanarFaces.Add(face);
                }
            }

            foreach (Solid solid in solids)
            {
                FaceArray    faces            = solid.Faces;
                IList <Face> solidPlanarFaces = new List <Face>();
                foreach (Face face in faces)
                {
                    if (face is PlanarFace)
                    {
                        solidPlanarFaces.Add(face);
                    }
                    else
                    {
                        nonPlanarFaces.Add(face);
                    }
                }

                if (solidPlanarFaces.Count() == faces.Size)
                {
                    foreach (Edge edge in solid.Edges)
                    {
                        edgesToTesselate.Add(edge);
                    }
                }
                else
                {
                    foreach (Face planarFace in solidPlanarFaces)
                    {
                        planarFaces.Add(planarFace);
                    }
                }
            }

            foreach (Face planarFace in planarFaces)
            {
                EdgeArrayArray edgeLoops = planarFace.EdgeLoops;
                foreach (EdgeArray edgeLoop in edgeLoops)
                {
                    foreach (Edge edge in edgeLoop)
                    {
                        edgesToTesselate.Add(edge);
                    }
                }
            }

            foreach (Edge edge in edgesToTesselate)
            {
                IList <XYZ> edgeVertices            = edge.Tessellate();
                IList <XYZ> transformedEdgeVertices = TransformVertexList(edgeVertices, trf);
                minBound = NewMinBound(minBound, transformedEdgeVertices);
                maxBound = NewMaxBound(maxBound, transformedEdgeVertices);
            }

            foreach (Face nonPlanarFace in nonPlanarFaces)
            {
                Mesh faceMesh = nonPlanarFace.Triangulate();
                polymeshes.Add(faceMesh);
            }

            foreach (Mesh mesh in polymeshes)
            {
                IList <XYZ> vertices            = mesh.Vertices;
                IList <XYZ> transformedVertices = TransformVertexList(vertices, trf);
                minBound = NewMinBound(minBound, transformedVertices);
                maxBound = NewMaxBound(maxBound, transformedVertices);
            }

            BoundingBoxXYZ boundingBox = new BoundingBoxXYZ();

            boundingBox.set_Bounds(0, minBound);
            boundingBox.set_Bounds(1, maxBound);
            return(boundingBox);
        }
Esempio n. 9
0
        static private BoundingBoxXYZ ProcessBoundingBox(IFCAnyHandle boundingBoxHnd)
        {
            IFCAnyHandle lowerLeftHnd = IFCAnyHandleUtil.GetInstanceAttribute(boundingBoxHnd, "Corner");
            XYZ minXYZ = IFCPoint.ProcessScaledLengthIFCCartesianPoint(lowerLeftHnd);

            double xDim = IFCAnyHandleUtil.GetDoubleAttribute(boundingBoxHnd, "XDim").Value;
            double yDim = IFCAnyHandleUtil.GetDoubleAttribute(boundingBoxHnd, "YDim").Value;
            double zDim = IFCAnyHandleUtil.GetDoubleAttribute(boundingBoxHnd, "ZDim").Value;

            XYZ maxXYZ = new XYZ(minXYZ.X + xDim, minXYZ.Y + yDim, minXYZ.Z + zDim);
            BoundingBoxXYZ boundingBox = new BoundingBoxXYZ();
            boundingBox.set_Bounds(0, minXYZ);
            boundingBox.set_Bounds(1, maxXYZ);
            return boundingBox;
        }
        private static BoundingBoxXYZ ComputeApproximateCurveLoopBBoxForOpening(CurveLoop curveLoop, Plane plane)
        {
            Transform trf = null;
            Transform trfInv = null;

            XYZ ll = null;
            XYZ ur = null;
            if (plane != null)
            {
                trf = Transform.Identity;
                trf.BasisX = plane.XVec;
                trf.BasisY = plane.YVec;
                trf.BasisZ = plane.Normal;
                trf.Origin = plane.Origin;
                trfInv = trf.Inverse;
            }

            bool init = false;
            foreach (Curve curve in curveLoop)
            {
                IList<XYZ> pts = new List<XYZ>();
                if (curve is Line) 
                {
                    pts.Add(curve.GetEndPoint(0));
                    pts.Add(curve.GetEndPoint(1));
                }
                else if (curve is Arc)
                {
                    ComputeArcBoundingBox(curve as Arc, pts);
                }
                else
                    pts = curve.Tessellate();

                foreach (XYZ pt in pts)
                {
                    XYZ ptToUse = (trf != null) ? trfInv.OfPoint(pt) : pt;
                    if (!init)
                    {
                        ll = ptToUse;
                        ur = ptToUse;
                        init = true;
                    }
                    else
                    {
                        ll = new XYZ(Math.Min(ll.X, ptToUse.X), Math.Min(ll.Y, ptToUse.Y), Math.Min(ll.Z, ptToUse.Z));
                        ur = new XYZ(Math.Max(ur.X, ptToUse.X), Math.Max(ur.Y, ptToUse.Y), Math.Max(ur.Z, ptToUse.Z));
                    }
                }
            }

            if (!init)
                return null;

            if (trf != null)
            {
                ll = trf.OfPoint(ll);
                ur = trf.OfPoint(ur);
            }

            BoundingBoxXYZ curveLoopBounds = new BoundingBoxXYZ();
            curveLoopBounds.set_Bounds(0, ll);
            curveLoopBounds.set_Bounds(1, ur);
            return curveLoopBounds;
        }
Esempio n. 11
0
        /// <summary>
        /// Sets the interior elevation view's cropbox based on the room's bounding box
        /// </summary>
        /// <param name="intElev">Interior Elevations</param>
        /// <param name="r">room</param>
        /// <returns>room bounding box</returns>
        public void SetCropBox(ViewSection intElev, Room r, XYZ markerPosition)
        {
            BoundingBoxXYZ iecb        = intElev.CropBox;
            XYZ            cbboundsmin = iecb.get_Bounds(0);
            XYZ            cbboundsmax = iecb.get_Bounds(1);

            Debug("room " + r.Name + r.Number);
            Debug("cbboundsmin " + cbboundsmin);
            Debug("cbboundsmax " + cbboundsmax);

            Debug("cb origin " + iecb.Transform.Origin);

            iecb.Transform.Origin = markerPosition;
            Debug("cb origin reset 1 " + iecb.Transform.Origin);

            BoundingBoxXYZ rbb    = r.get_BoundingBox(null);
            XYZ            rbbmin = rbb.get_Bounds(0);
            XYZ            rbbmax = rbb.get_Bounds(1);

            Debug("rbbmin " + rbbmin);
            Debug("rbbmax " + rbbmax);

            Debug("rbb origin " + rbb.Transform.Origin);

            double[][] transform = Matrix.transform2matrix(iecb.Transform);

            double centerOffsetX = markerPosition.X - iecb.Transform.Origin.X;
            double centerOffsetY = markerPosition.Y - iecb.Transform.Origin.Y;

            XYZ offsetVector = new XYZ(
                centerOffsetX,
                centerOffsetY,
                0);

            double[] offsetMatrix  = Matrix.xyz2matrix(offsetVector);
            double[] offsetTMatrix = Matrix.dot(transform, offsetMatrix);
            XYZ      offsetT       = new XYZ(
                offsetTMatrix[0],
                offsetTMatrix[1],
                offsetTMatrix[2]);

            //double[] minXMatrix = Matrix.xyz2matrix(new XYZ(cbboundsmin.X, 0, 0));
            //double[] maxXMatrix = Matrix.xyz2matrix(new XYZ(cbboundsmax.X, 0, 0));
            //double[] minXTMatrix = Matrix.dot(transform, minXMatrix);
            //double[] maxXTMatrix = Matrix.dot(transform, maxXMatrix);

            double transformangle  = Math.Atan2(offsetVector.Y, offsetVector.X);
            double transformangle2 = Math.Acos(transform[0][0]);

            Debug("transformangle " + transformangle + ", " + (transformangle * 180 / Math.PI));
            Debug("transformangle2 " + transformangle2 + ", " + (transformangle2 * 180 / Math.PI));

            double transformanglePos = transformangle < 0 ? Math.PI + transformangle : transformangle;

            int transformangleRounded = (int)(Math.Round(transformanglePos * 100));

            Debug("transformangleRounded " + transformangleRounded);

            var segments = r.GetBoundarySegments(new SpatialElementBoundaryOptions()).FirstOrDefault();

            if (segments == null)
            {
                Debug("null segments");
                return;
            }

            double wallLength = 4;

            foreach (var s in segments)
            {
                var c   = s.GetCurve();
                var ep1 = c.GetEndPoint(0);
                var ep2 = c.GetEndPoint(1);

                double rise = ep2.Y - ep1.Y;
                double run  = ep2.X - ep1.X;

                double angle    = Math.Atan2(rise, run);
                double anglePos = angle < 0 ? Math.PI + angle : angle;

                int angleRounded = (int)(Math.Round(anglePos * 100));

                double length = Math.Sqrt(Math.Pow(rise, 2) + Math.Pow(run, 2));

                if (angleRounded == transformangleRounded && length > wallLength)
                {
                    wallLength = length;
                    Debug("selected wallLength " + wallLength);
                }

                Debug("angle " + angle + ", " + (angle * 180 / Math.PI));
                Debug("angleRounded " + angleRounded);
                Debug("length " + length);
            }

            Debug("centerOffset v " + offsetVector);
            Debug("centerOffset vT " + offsetT);

            Debug("wallLength " + wallLength);

            XYZ newcbmin = new XYZ(
                offsetT.X - wallLength / 2 - 1,
                rbbmin.Z - 1,
                cbboundsmin.Z);

            XYZ newcbmax = new XYZ(
                offsetT.X + wallLength / 2 + 1,
                rbbmax.Z + 1,
                cbboundsmax.Z);



            iecb.set_Bounds(0, newcbmin);
            iecb.set_Bounds(1, newcbmax);

            Debug("reset bounds 0 " + iecb.get_Bounds(0));
            Debug("reset bounds 1 " + iecb.get_Bounds(1));

            intElev.CropBox        = iecb;
            intElev.CropBoxVisible = false;

            Debug("cb origin reset 2 " + iecb.Transform.Origin);
        }
Esempio n. 12
0
        public BoundingBoxXYZ SetCropBox(ViewSection intElev, Room r)
        {
            BoundingBoxXYZ iecb        = intElev.CropBox;
            XYZ            cbboundsmin = iecb.get_Bounds(0);
            XYZ            cbboundsmax = iecb.get_Bounds(1);

            BoundingBoxXYZ rbb    = r.get_BoundingBox(null);
            XYZ            rbbmin = rbb.get_Bounds(0);
            XYZ            rbbmax = rbb.get_Bounds(1);

            double[][] transform = Matrix.transform2matrix(iecb.Transform);

            XYZ rbbmintransformed = new XYZ
                                    (
                rbbmin.X * transform[0][0] + rbbmin.Y * transform[0][1] + rbbmin.Z * transform[0][2],
                rbbmin.X * transform[1][0] + rbbmin.Y * transform[1][1] + rbbmin.Z * transform[1][2],
                rbbmin.X * transform[2][0] + rbbmin.Y * transform[2][1] + rbbmin.Z * transform[2][2]
                                    );

            XYZ rbbmaxtransformed = new XYZ
                                    (
                rbbmax.X * transform[0][0] + rbbmax.Y * transform[0][1] + rbbmax.Z * transform[0][2],
                rbbmax.X * transform[1][0] + rbbmax.Y * transform[1][1] + rbbmax.Z * transform[1][2],
                rbbmax.X * transform[2][0] + rbbmax.Y * transform[2][1] + rbbmax.Z * transform[2][2]
                                    );

            double minX = rbbmintransformed.X < rbbmaxtransformed.X ? rbbmintransformed.X : rbbmaxtransformed.X;
            double minY = rbbmintransformed.Y < rbbmaxtransformed.Y ? rbbmintransformed.Y : rbbmaxtransformed.Y;

            double maxX = rbbmintransformed.X > rbbmaxtransformed.X ? rbbmintransformed.X : rbbmaxtransformed.X;
            double maxY = rbbmintransformed.Y > rbbmaxtransformed.Y ? rbbmintransformed.Y : rbbmaxtransformed.Y;

            XYZ rbbboundsmin = new XYZ(
                minX,
                minY,
                cbboundsmin.Z);
            XYZ rbbboundsmax = new XYZ(
                maxX,
                maxY,
                cbboundsmax.Z);


            BoundingBoxXYZ rbbtransformed = new BoundingBoxXYZ();

            rbbtransformed.set_Bounds(0, rbbboundsmin);
            rbbtransformed.set_Bounds(1, rbbboundsmax);


            XYZ rbbboundsminextended = new XYZ(
                minX - 1,
                minY - 1,
                cbboundsmin.Z);
            XYZ rbbboundsmaxextended = new XYZ(
                maxX + 1,
                maxY + 1,
                cbboundsmax.Z);


            intElev.CropBox.Min = rbbboundsminextended;
            intElev.CropBox.Max = rbbboundsmaxextended;
            iecb.set_Bounds(0, rbbboundsminextended);
            iecb.set_Bounds(1, rbbboundsmaxextended);
            intElev.CropBox        = iecb;
            intElev.CropBoxVisible = false;

            return(rbb);
        }
Esempio n. 13
0
        private OrthogonalCamera GetOrthogonalCamera(Dictionary <int, ElementProperties> elementDictionary, string imagePath)
        {
            OrthogonalCamera orthoCamera = new OrthogonalCamera();

            try
            {
                BoundingBoxXYZ boundingBox = new BoundingBoxXYZ();
                boundingBox.Enabled = true;
                for (int i = 0; i < 3; i++)
                {
                    boundingBox.set_MinEnabled(i, true);
                    boundingBox.set_MaxEnabled(i, true);
                    boundingBox.set_BoundEnabled(0, i, true);
                    boundingBox.set_BoundEnabled(1, i, true);
                }

                BoundingBoxXYZ tempBoundingBox = elementDictionary.First().Value.RevitElement.get_BoundingBox(null);
                tempBoundingBox.Enabled = true;

                double maxX = tempBoundingBox.Max.X;
                double maxY = tempBoundingBox.Max.Y;
                double maxZ = tempBoundingBox.Max.Z;
                double minX = tempBoundingBox.Min.X;
                double minY = tempBoundingBox.Min.Y;
                double minZ = tempBoundingBox.Min.Z;

                List <ElementId>           elementIds = new List <ElementId>();
                Dictionary <int, Category> categories = new Dictionary <int, Category>();
                foreach (ElementProperties ep in elementDictionary.Values)
                {
                    Element element = ep.RevitElement;
                    if (null != element)
                    {
                        try
                        {
                            if (!categories.ContainsKey(element.Category.Id.IntegerValue))
                            {
                                categories.Add(element.Category.Id.IntegerValue, element.Category);
                            }
                            BoundingBoxXYZ bbBox = element.get_BoundingBox(null);
                            bbBox.Enabled = true;
                            elementIds.Add(element.Id);
                            if (null != boundingBox)
                            {
                                if (bbBox.Max.X > maxX)
                                {
                                    maxX = bbBox.Max.X;
                                }
                                if (bbBox.Max.Y > maxY)
                                {
                                    maxY = bbBox.Max.Y;
                                }
                                if (bbBox.Max.Z > maxZ)
                                {
                                    maxZ = bbBox.Max.Z;
                                }
                                if (bbBox.Min.X < minX)
                                {
                                    minX = bbBox.Min.X;
                                }
                                if (bbBox.Min.Y < minY)
                                {
                                    minY = bbBox.Min.Y;
                                }
                                if (bbBox.Min.Z < minZ)
                                {
                                    minZ = bbBox.Min.Z;
                                }
                            }
                        }
                        catch
                        {
                            continue;
                        }
                    }
                }

                XYZ xyzMax = new XYZ(maxX, maxY, maxZ);
                XYZ xyzMin = new XYZ(minX, minY, minZ);

                boundingBox.set_Bounds(0, xyzMin);
                boundingBox.set_Bounds(1, xyzMax);


                ViewFamilyType           view3dFamilyType = null;
                FilteredElementCollector collector        = new FilteredElementCollector(m_doc);
                List <Element>           elements         = collector.OfClass(typeof(ViewFamilyType)).ToElements().ToList();
                foreach (Element element in elements)
                {
                    ViewFamilyType viewfamilytype = element as ViewFamilyType;
                    if (viewfamilytype.ViewFamily == ViewFamily.ThreeDimensional)
                    {
                        view3dFamilyType = viewfamilytype; break;
                    }
                }

                if (null != view3dFamilyType)
                {
                    using (TransactionGroup transGroup = new TransactionGroup(m_doc))
                    {
                        transGroup.Start("Start Creating View 3D");
                        using (Transaction trans = new Transaction(m_doc))
                        {
                            trans.Start("Create View");

                            View3D view3d = View3D.CreateIsometric(m_doc, view3dFamilyType.Id);
                            view3d.SetSectionBox(boundingBox);
                            view3d.GetSectionBox().Enabled = true;
                            view3d.DetailLevel = ViewDetailLevel.Fine;

                            foreach (Category category in categories.Values)
                            {
                                if (category.get_AllowsVisibilityControl(view3d))
                                {
#if RELEASE2017 || RELEASE2018
                                    view3d.SetCategoryHidden(category.Id, false);
#else
                                    view3d.SetVisibility(category, true);
#endif
                                }
                            }

                            view3d.get_Parameter(BuiltInParameter.MODEL_GRAPHICS_STYLE).Set(4);

                            //m_app.ActiveUIDocument.ActiveView = view3d;
                            //m_app.ActiveUIDocument.RefreshActiveView();

                            XYZ   eyePostion = view3d.GetOrientation().EyePosition;
                            Point viewPoint  = new Point();
                            viewPoint.X = eyePostion.X; viewPoint.Y = eyePostion.Y; viewPoint.Z = eyePostion.Z;
                            orthoCamera.CameraViewPoint = viewPoint;

                            XYZ       forwardDirection = view3d.GetOrientation().ForwardDirection;
                            Direction fDirection       = new Direction();
                            fDirection.X = forwardDirection.X; fDirection.Y = forwardDirection.Y; fDirection.Z = forwardDirection.Z;
                            orthoCamera.CameraDirection = fDirection;

                            XYZ       upDirection = view3d.GetOrientation().UpDirection;
                            Direction uDirection  = new Direction();
                            uDirection.X = upDirection.X; uDirection.Y = upDirection.Y; uDirection.Z = upDirection.Z;
                            orthoCamera.CameraUpVector = uDirection;

                            orthoCamera.ViewToWorldScale = view3d.Scale;
                            m_app.ActiveUIDocument.RefreshActiveView();
                            trans.Commit();

                            trans.Start("Export Image");
                            //create snapshot.png
                            ImageExportOptions option = new ImageExportOptions();
                            option.HLRandWFViewsFileType = ImageFileType.PNG;
                            option.ImageResolution       = ImageResolution.DPI_300;
                            option.ShouldCreateWebSite   = false;
                            option.ExportRange           = ExportRange.SetOfViews;
                            option.FilePath = imagePath;
                            List <ElementId> viewIds = new List <ElementId>();
                            viewIds.Add(view3d.Id);
                            option.SetViewsAndSheets(viewIds);

                            if (ImageExportOptions.IsValidFileName(option.FilePath))
                            {
                                m_doc.ExportImage(option);
                            }
                            trans.Commit();
                        }
                        transGroup.RollBack();
                    }

                    if (File.Exists(imagePath))
                    {
                        File.Delete(imagePath);
                    }
                    string[] fileNames = Directory.GetFiles(Path.GetDirectoryName(imagePath), "snapshot*");
                    foreach (string fName in fileNames)
                    {
                        if (Path.GetExtension(fName) == ".png" || Path.GetExtension(fName) == ".jpg")
                        {
                            File.Move(fName, imagePath);
                            if (File.Exists(fName))
                            {
                                File.Delete(fName);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to get the orthogonal camera.\n" + ex.Message, "Get Orthogonal Camera", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(orthoCamera);
        }