Пример #1
0
        /// <summary>
        /// Processes an IfcTypeObject.
        /// </summary>
        /// <param name="ifcTypeObject">The IfcTypeObject handle.</param>
        /// <returns>The IFCTypeObject object.</returns>
        public static IFCTypeObject ProcessIFCTypeObject(IFCAnyHandle ifcTypeObject)
        {
            if (IFCAnyHandleUtil.IsNullOrHasNoValue(ifcTypeObject))
            {
                IFCImportFile.TheLog.LogNullError(IFCEntityType.IfcTypeObject);
                return null;
            }

            IFCEntity typeObject;
            if (IFCImportFile.TheFile.EntityMap.TryGetValue(ifcTypeObject.StepId, out typeObject))
                return (typeObject as IFCTypeObject);

            if (IFCAnyHandleUtil.IsSubTypeOf(ifcTypeObject, IFCEntityType.IfcTypeProduct))
            {
                return IFCTypeProduct.ProcessIFCTypeProduct(ifcTypeObject);
            }

            return new IFCTypeObject(ifcTypeObject);
        }
        /// <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);
                    }
                }
            }
        }
Пример #3
0
        private void RegisterRepresentationMapWithTypeProject(IFCRepresentationMap representationMap, IFCTypeProduct typeProduct)
        {
            if (representationMap == null || typeProduct == null)
            {
                return;
            }

            // Note that if the representation map is already in the RepMapToTypeProduct map, we null out the entry, but keep it.
            // That prevents future attempts to register the representation map.
            if (Importer.TheCache.RepMapToTypeProduct.ContainsKey(representationMap.Id))
            {
                Importer.TheCache.RepMapToTypeProduct[representationMap.Id] = null;
            }
            else
            {
                Importer.TheCache.RepMapToTypeProduct[representationMap.Id] = typeProduct;
            }
        }
Пример #4
0
        private void RegisterRepresentationMapWithTypeProject(IFCRepresentationMap representationMap, IFCTypeProduct typeProduct)
        {
            if (representationMap == null || representationMap.MappedRepresentation == null || typeProduct == null)
            {
                return;
            }

            // Note that if the representation map is already in the RepMapToTypeProduct map, or we have already found
            // a representation of the same type, then we null out the entry, but keep it.
            // That prevents future attempts to register the representation map.
            if (Importer.TheCache.RepMapToTypeProduct.ContainsKey(representationMap.Id))
            {
                Importer.TheCache.RepMapToTypeProduct[representationMap.Id] = null;
                return;
            }

            string repType = representationMap.MappedRepresentation.Type;

            if (repType == null)
            {
                repType = string.Empty;
            }

            ISet <string> typeProductLabels = null;

            if (Importer.TheCache.TypeProductToRepLabel.TryGetValue(typeProduct.Id, out typeProductLabels) &&
                typeProductLabels != null && typeProductLabels.Contains(repType))
            {
                // We expect a TypeProduct to only have one Representation of each type.  In the case
                // that we find a 2nd representation of the same type, we will refuse to add it.
                Importer.TheCache.RepMapToTypeProduct[representationMap.Id] = null;
                return;
            }

            if (typeProductLabels == null)
            {
                Importer.TheCache.TypeProductToRepLabel[typeProduct.Id] = new HashSet <string>();
            }

            Importer.TheCache.RepMapToTypeProduct[representationMap.Id] = typeProduct;
            Importer.TheCache.TypeProductToRepLabel[typeProduct.Id].Add(repType);
        }