Example #1
0
        /// <summary>
        /// Reverses curve loop.
        /// </summary>
        /// <param name="curveloop">
        /// The curveloop.
        /// </param>
        /// <returns>
        /// The reversed curve loop.
        /// </returns>
        public static CurveLoop ReverseOrientation(CurveLoop curveloop)
        {
            CurveLoop copyOfCurveLoop = CurveLoop.CreateViaCopy(curveloop);

            copyOfCurveLoop.Flip();
            return(copyOfCurveLoop);
        }
Example #2
0
        /// <summary>
        /// Copies the crop region and rotation of one view and applies it to another. Useful for creating views with identical cropping at different levels in a project.
        /// </summary>
        /// <param name="source">The source view.</param>
        /// <param name="target">The target view.</param>
        /// <returns></returns>
        public static Revit.Elements.Views.View CopyCrop(Revit.Elements.Views.View source, Revit.Elements.Views.View target)
        {
            var doc = DocumentManager.Instance.CurrentDBDocument;

            var iSourceView = source.InternalElement as Autodesk.Revit.DB.View;
            var iTargetView = target.InternalElement as Autodesk.Revit.DB.View;

            var sourceCropRegion = GetViewCrop(iSourceView).cropRegion;

            TransactionManager.Instance.EnsureInTransaction(doc);

            SetRotation(target, GetRotation(source));

            iTargetView.CropBoxVisible = true;
            iTargetView.GetCropRegionShapeManager().SetCropShape(CurveLoop.CreateViaCopy(sourceCropRegion));

            // SUPER IMPORTANT TO REGENERATE THE DOCUMENT AFTER THE WORK IS DONE!
            DocumentManager.Regenerate();
            TransactionManager.Instance.TransactionTaskDone();

            return(target);
        }
        /// <summary>
        /// Return geometry for a particular representation item.
        /// </summary>
        /// <param name="shapeEditScope">The shape edit scope.</param>
        /// <param name="lcs">Local coordinate system for the geometry.</param>
        /// <param name="guid">The guid of an element for which represntation is being created.</param>
        /// <returns>One or more created geometries.</returns>
        /// <remarks>The scaledLcs is only partially supported in this routine; it allows scaling the depth of the extrusion,
        /// which is commonly found in ACA files.</remarks>
        protected override IList <GeometryObject> CreateGeometryInternal(
            IFCImportShapeEditScope shapeEditScope, Transform lcs, Transform scaledLcs, string guid)
        {
            if (Direction == null)
            {
                Importer.TheLog.LogError(Id, "Error processing IfcExtrudedAreaSolid, can't create geometry.", false);
                return(null);
            }

            Transform origLCS       = (lcs == null) ? Transform.Identity : lcs;
            Transform origScaledLCS = (scaledLcs == null) ? Transform.Identity : scaledLcs;

            Transform unscaledExtrusionPosition = (Position == null) ? origLCS : origLCS.Multiply(Position);
            Transform scaledExtrusionPosition   = (Position == null) ? origScaledLCS : origScaledLCS.Multiply(Position);

            XYZ scaledExtrusionDirection = scaledExtrusionPosition.OfVector(Direction);

            ISet <IList <CurveLoop> > disjointLoops = GetTransformedCurveLoops(unscaledExtrusionPosition, scaledExtrusionPosition);

            if (disjointLoops == null || disjointLoops.Count() == 0)
            {
                return(null);
            }

            IList <GeometryObject> extrusions = new List <GeometryObject>();

            foreach (IList <CurveLoop> originalLoops in disjointLoops)
            {
                SolidOptions solidOptions    = new SolidOptions(GetMaterialElementId(shapeEditScope), shapeEditScope.GraphicsStyleId);
                XYZ          scaledDirection = scaledExtrusionPosition.OfVector(Direction);
                double       currDepth       = Depth * scaledDirection.GetLength();

                IList <CurveLoop> loops = new List <CurveLoop>();
                foreach (CurveLoop originalLoop in originalLoops)
                {
                    if (!originalLoop.IsOpen())
                    {
                        loops.Add(originalLoop);
                        continue;
                    }

                    if (originalLoop.Count() > 0)
                    {
                        try
                        {
                            // We will attempt to close the loop to make it usable.
                            XYZ       startPoint      = originalLoop.First().GetEndPoint(0);
                            XYZ       endPoint        = originalLoop.Last().GetEndPoint(1);
                            Line      closingLine     = Line.CreateBound(endPoint, startPoint);
                            CurveLoop healedCurveLoop = CurveLoop.CreateViaCopy(originalLoop);
                            healedCurveLoop.Append(closingLine);
                            loops.Add(healedCurveLoop);
                            Importer.TheLog.LogWarning(Id, "Extrusion has an open profile loop, fixing.", false);
                            continue;
                        }
                        catch
                        {
                        }
                    }

                    Importer.TheLog.LogError(Id, "Extrusion has an open profile loop, ignoring.", false);
                }

                if (loops.Count == 0)
                {
                    continue;
                }

                GeometryObject extrusionObject = null;
                try
                {
                    // We may try to create separate extrusions, one per layer here.
                    bool      shouldWarn         = false;
                    ElementId overrideMaterialId = ElementId.InvalidElementId;

                    if (shapeEditScope.Creator.MaterialSelect != null)
                    {
                        if (shapeEditScope.Creator.MaterialSelect is IFCMaterialLayerSetUsage)
                        {
                            IList <GeometryObject> extrusionLayers = CreateGeometryFromMaterialLayerUsage(shapeEditScope, scaledExtrusionPosition, loops,
                                                                                                          scaledExtrusionDirection, currDepth, out overrideMaterialId, out shouldWarn);
                            if (extrusionLayers == null || extrusionLayers.Count == 0)
                            {
                                if (shouldWarn)
                                {
                                    Importer.TheLog.LogWarning(Id, "Couldn't process associated IfcMaterialLayerSetUsage, using body geometry instead.", false);
                                }
                                if (overrideMaterialId != ElementId.InvalidElementId)
                                {
                                    solidOptions.MaterialId = overrideMaterialId;
                                }
                                extrusionObject = GeometryCreationUtilities.CreateExtrusionGeometry(loops, scaledExtrusionDirection, currDepth, solidOptions);
                            }
                            else
                            {
                                foreach (GeometryObject extrusionLayer in extrusionLayers)
                                {
                                    extrusions.Add(extrusionLayer);
                                }
                            }
                        }
                        else if (shapeEditScope.Creator.MaterialSelect is IFCMaterialProfileSetUsage)
                        {
                            extrusionObject = CreateGeometryFromMaterialProfile(shapeEditScope, loops, scaledExtrusionDirection, currDepth, solidOptions, out shouldWarn);
                            if (extrusionObject == null)
                            {
                                extrusionObject = GeometryCreationUtilities.CreateExtrusionGeometry(loops, scaledExtrusionDirection, currDepth, solidOptions);
                            }
                        }
                        else
                        {
                            extrusionObject = GeometryCreationUtilities.CreateExtrusionGeometry(loops, scaledExtrusionDirection, currDepth, solidOptions);
                        }
                    }
                    else
                    {
                        extrusionObject = GeometryCreationUtilities.CreateExtrusionGeometry(loops, scaledExtrusionDirection, currDepth, solidOptions);
                    }
                }
                catch (Exception ex)
                {
                    extrusionObject = GetMeshBackup(shapeEditScope, loops, scaledExtrusionDirection, currDepth);
                    if (extrusionObject == null)
                    {
                        throw ex;
                    }
                }

                if (extrusionObject != null)
                {
                    if (!(extrusionObject is Solid) || IFCGeometryUtil.ValidateGeometry(extrusionObject as Solid))
                    {
                        extrusions.Add(extrusionObject);
                    }
                    else
                    {
                        Mesh meshBackup = GetMeshBackup(shapeEditScope, loops, scaledExtrusionDirection, currDepth);
                        if (meshBackup != null)
                        {
                            extrusions.Add(meshBackup);
                        }
                    }
                }
            }

            return(extrusions);
        }