コード例 #1
0
        public IfcShapeRepresentation NewGeometricRepresentation(IfcProduct product,
                                                                 IfcGeometricRepresentationItem representationItem,
                                                                 IfcStyleAssignmentSelect style = null,
                                                                 string representationContext   = "Model",
                                                                 string representationContextId = "Body")
        {
            if (Store != product.Model || Store != representationItem.Model)
            {
                throw new ArgumentException("Model mismatch");
            }

            IfcShapeRepresentation shapeRepresentation = null;

            Wrap(s =>
            {
                var productDefinitionShape = product.Representation;
                if (null == productDefinitionShape)
                {
                    productDefinitionShape = s.Instances.New <IfcProductDefinitionShape>();
                }

                if (null != style)
                {
                    s.Instances.New <IfcStyledItem>(i =>
                    {
                        i.Item = representationItem;
                        i.Styles.Add(style);
                    });
                }

                product.Representation = productDefinitionShape;

                shapeRepresentation = s.Instances.New <IfcShapeRepresentation>();
                productDefinitionShape.Representations.Add(shapeRepresentation);

                var project  = Scopes.OfType <IfcProject>().FirstOrDefault();
                var contexts = project
                               .RepresentationContexts
                               .Where <IfcGeometricRepresentationContext>(c => c.ContextType == representationContext);

                IfcGeometricRepresentationContext context = null;
                if (contexts.Count() > 1)
                {
                    context = contexts.Where(c => c.ContextIdentifier == representationContextId).FirstOrDefault();
                }
                else
                {
                    context = contexts.FirstOrDefault();
                }

                if (null == context)
                {
                    context = Store.NewIfc4GeometricContext(representationContextId, representationContext);
                }

                shapeRepresentation.ContextOfItems = context;
                shapeRepresentation.Items.Add(representationItem);
            });

            return(shapeRepresentation);
        }