コード例 #1
0
        private IfcShapeRepresentation CreateShapeRepresentation(IfcRepresentationContext context,
                                                                 Representation representation)
        {
            //create presentation styles
            var presentationStyleDictionary = new Dictionary <String, IfcPresentationStyle>();

            foreach (Material material in representation.materials)
            {
                try
                {
                    presentationStyleDictionary.Add(material.id,
                                                    IfcInit.CreateSurfaceStyle(material.name,
                                                                               material.color,
                                                                               material.metal,
                                                                               material.roughness));
                }
                catch (ArgumentException ex)
                {
                    throw new ArgumentException(string.Format("Material with id {0} already exists", material.id),
                                                "materials", ex);
                }
            }

            //create representation items
            var representationItemList = new List <IfcRepresentationItem>();

            foreach (RepresentationItem item in representation.representationItems)
            {
                IfcRepresentationItem representationItem;
                try
                {
                    representationItem = RepresentationParser.ParseConstructionString(item.constructionString);
                }
                catch (ArgumentException ex)
                {
                    var errors = new Dictionary <string, string[]>();
                    errors.Add(ex.ParamName, new string[] { ex.Message });
                    throw new ValidationException(errors, ex.Message);
                }

                if (item.transformation != null)
                {
                    representationItem.ApplyQuaternion(new Quaternion(item.transformation.rotation))
                    .Translate(item.transformation.translation);
                }

                if (item.material != null)
                {
                    IfcPresentationStyle surfaceStyle;
                    if (presentationStyleDictionary.TryGetValue(item.material, out surfaceStyle))
                    {
                        representationItem.StyledBy(new IfcPresentationStyle[] { surfaceStyle });
                    }
                }

                representationItemList.Add(representationItem);
            }
            return(new IfcShapeRepresentation(context,
                                              new IfcLabel("Body"),
                                              new IfcLabel("SolidModel"),
                                              representationItemList.ToArray()));
        }