Exemplo n.º 1
0
        /// <summary>
        /// Creates or populates Revit elements based on the information contained in this class.
        /// </summary>
        /// <param name="doc">The document.</param>
        protected override void Create(Document doc)
        {
            DirectShapeType shapeType = Importer.TheCache.UseElementByGUID <DirectShapeType>(doc, GlobalId);

            if (shapeType == null)
            {
                shapeType = DirectShapeType.Create(doc, GetName("DirectShapeType"), IFCElementUtil.GetDSValidCategoryId(doc, CategoryId, Id));
            }

            if (shapeType == null)
            {
                throw new InvalidOperationException("Couldn't create DirectShapeType for IfcTypeObject.");
            }

            m_CreatedElementId = shapeType.Id;

            base.Create(doc);

            TraverseSubElements(doc);
        }
        /// <summary>
        /// Create geometry for a particular representation map.
        /// </summary>
        /// <param name="shapeEditScope">The geometry creation scope.</param>
        /// <param name="lcs">Local coordinate system for the geometry, without scale.</param>
        /// <param name="scaledLcs">Local coordinate system for the geometry, including scale, potentially non-uniform.</param>
        /// <remarks>For this function, if lcs is null, we will create a library item for the geometry.</remarks>
        public void CreateShape(IFCImportShapeEditScope shapeEditScope, Transform lcs, Transform scaledLcs, string guid)
        {
            bool creatingLibraryDefinition = (lcs == null);

            if (MappedRepresentation != null)
            {
                // Look for cached shape; if found, return.
                if (creatingLibraryDefinition)
                {
                    if (IFCImportFile.TheFile.ShapeLibrary.FindDefinitionType(Id.ToString()) != ElementId.InvalidElementId)
                    {
                        return;
                    }
                }

                Transform mappingTransform = null;
                if (lcs == null)
                {
                    mappingTransform = MappingOrigin;
                }
                else
                {
                    if (MappingOrigin == null)
                    {
                        mappingTransform = lcs;
                    }
                    else
                    {
                        mappingTransform = lcs.Multiply(MappingOrigin);
                    }
                }

                Transform scaledMappingTransform = null;
                if (scaledLcs == null)
                {
                    scaledMappingTransform = mappingTransform;
                }
                else
                {
                    if (MappingOrigin == null)
                    {
                        scaledMappingTransform = scaledLcs;
                    }
                    else
                    {
                        scaledMappingTransform = scaledLcs.Multiply(MappingOrigin);
                    }
                }

                int numExistingSolids = shapeEditScope.Creator.Solids.Count;
                int numExistingCurves = shapeEditScope.Creator.FootprintCurves.Count;

                MappedRepresentation.CreateShape(shapeEditScope, mappingTransform, scaledMappingTransform, guid);

                if (creatingLibraryDefinition)
                {
                    int numNewSolids = shapeEditScope.Creator.Solids.Count;
                    int numNewCurves = shapeEditScope.Creator.FootprintCurves.Count;

                    if ((numExistingSolids != numNewSolids) || (numExistingCurves != numNewCurves))
                    {
                        IList <GeometryObject> mappedSolids = new List <GeometryObject>();
                        for (int ii = numExistingSolids; ii < numNewSolids; ii++)
                        {
                            mappedSolids.Add(shapeEditScope.Creator.Solids[numExistingSolids].GeometryObject);
                            shapeEditScope.Creator.Solids.RemoveAt(numExistingSolids);
                        }

                        IList <Curve> mappedCurves = new List <Curve>();
                        for (int ii = numExistingCurves; ii < numNewCurves; ii++)
                        {
                            mappedCurves.Add(shapeEditScope.Creator.FootprintCurves[numExistingCurves]);
                            shapeEditScope.Creator.FootprintCurves.RemoveAt(numExistingCurves);
                        }
                        shapeEditScope.AddPlanViewCurves(mappedCurves, Id);

                        //IFCImportFile.TheFile.ShapeLibrary.AddDefinition(Id.ToString(), mappedItems);

                        Document        doc             = IFCImportFile.TheFile.Document;
                        DirectShapeType directShapeType = DirectShapeType.Create(doc, Id.ToString(), IFCElementUtil.GetDSValidCategoryId(doc, shapeEditScope.CategoryId, Id));
                        directShapeType.SetShape(mappedSolids);
                        shapeEditScope.SetPlanViewRep(directShapeType);

                        IFCImportFile.TheFile.ShapeLibrary.AddDefinitionType(Id.ToString(), directShapeType.Id);
                    }
                }
            }
        }