/// <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 = IFCElementUtil.CreateElementType(doc, GetVisibleName(), CategoryId, Id); } else { // If we used the element from the cache, we want to make sure that the IFCRepresentationMap can access it // instead of creating a new element. Importer.TheCache.CreatedDirectShapeTypes[Id] = shapeType.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); Document doc = IFCImportFile.TheFile.Document; DirectShapeType directShapeType = null; IFCTypeProduct typeProduct = null; if (Importer.TheCache.RepMapToTypeProduct.TryGetValue(Id, out typeProduct)) { ElementId directShapeTypeId = ElementId.InvalidElementId; if (Importer.TheCache.CreatedDirectShapeTypes.TryGetValue(typeProduct.Id, out directShapeTypeId)) { directShapeType = doc.GetElement(directShapeTypeId) as DirectShapeType; } } if (directShapeType == null) { string directShapeTypeName = Id.ToString(); directShapeType = IFCElementUtil.CreateElementType(doc, directShapeTypeName, shapeEditScope.CategoryId, Id); } // Note that this assumes that there is only one 2D rep per DirectShapeType. directShapeType.AppendShape(mappedSolids); if (mappedCurves.Count != 0) { shapeEditScope.SetPlanViewRep(directShapeType); } IFCImportFile.TheFile.ShapeLibrary.AddDefinitionType(Id.ToString(), directShapeType.Id); } } } }