public IfcRepresentationMap(IfcAxis2Placement __MappingOrigin, IfcRepresentation __MappedRepresentation) { this.MappingOrigin = __MappingOrigin; this.MappedRepresentation = __MappedRepresentation; this.HasShapeAspects = new HashSet <IfcShapeAspect>(); this.MapUsage = new HashSet <IfcMappedItem>(); }
public void AddRepresentation(IfcRepresentation representation) { if (this.Representation == null) { this.Representation = new IfcProductDefinitionShape(); } this.Representation.Representations.Add(representation); }
/// <summary> /// returns a Hash for the geometric behaviour of this object /// </summary> /// <param name="solid"></param> /// <returns></returns> public static int GetGeometryHashCode(this IfcRepresentation rep) { int hash = 0; foreach (var item in rep.Items) { hash ^= item.GetGeometryHashCode(); } return(hash); }
/// <summary> /// returns true if the representation is a 3D Shape (solid or surface), if it is a curve or curve set returns false /// </summary> /// <param name="rep"></param> /// <returns></returns> public static bool IsBodyRepresentation(this IfcRepresentation rep) { //in old models sometimes the representation is not defined so assume it is a candidate if (!rep.RepresentationIdentifier.HasValue || string.IsNullOrEmpty(rep.RepresentationIdentifier.Value)) { return(true); } string repIdentifier = rep.RepresentationIdentifier.Value; //if it is defined as body then it is candidate but exclude if it is using a line base representation if (string.Compare(repIdentifier, "body", true) == 0 || string.Compare(repIdentifier, "facetation", true) == 0) { //this should always be defined in an ifc2x3 schema but if it is not assume a solid if (!rep.RepresentationType.HasValue) { return(true); } string repType = rep.RepresentationType.Value; repType = repType.ToLowerInvariant(); //ignore line based body representations //if (repType == "curve2d" || repType == "geometricset" || repType == "geometriccurveset" || repType == "annotation2d") return false; //make sure we have a valid solid switch (repType) { case "solidmodel": case "surfacemodel": case "sweptsolid": case "brep": case "csg": case "clipping": case "advancedsweptsolid": case "boundingbox": case "sectionedspine": case "mappedrepresentation": return(true); case "geometricset": case "geometriccurveset": case "annotation2d": case "curve2d": default: return(false); } } else { return(false); } }
public override void Parse(int propIndex, IPropertyValue value, int[] nestedIndex) { switch (propIndex) { case 0: _mappingOrigin = (IfcAxis2Placement)(value.EntityVal); return; case 1: _mappedRepresentation = (IfcRepresentation)(value.EntityVal); return; default: throw new XbimParserException(string.Format("Attribute index {0} is out of range for {1}", propIndex + 1, GetType().Name.ToUpper())); } }
public virtual void IfcParse(int propIndex, IPropertyValue value) { switch (propIndex) { case 0: _mappingOrigin = (IfcAxis2Placement)value.EntityVal; break; case 1: _mappedRepresentation = (IfcRepresentation)value.EntityVal; break; default: this.HandleUnexpectedAttribute(propIndex, value); break; } }
/// <summary> /// Compares two objects for geomtric equality /// </summary> /// <param name="a"></param> /// <param name="b">object to compare with</param> /// <returns></returns> public static bool GeometricEquals(this IfcRepresentation a, IfcRepresentation b) { if (a.Equals(b)) { return(true); } List <IfcRepresentationItem> aRep = a.Items.ToList(); List <IfcRepresentationItem> bRep = b.Items.ToList(); for (int i = 0; i < aRep.Count; i++) { if (!aRep[i].GeometricEquals(bRep[i])) { return(false); } } return(true); }
public static Entity getEntityFromIfcRepresentation(IfcRepresentation rep, ViewportLayout viewportLayout1, Transformation entityTrs = null) { List <Entity> entityList = new List <Entity>(); if (viewportLayout1.Blocks.ContainsKey("Representation " + rep.Index.ToString())) { return(new IfcBlockReference("Representation " + rep.Index.ToString())); } foreach (IfcRepresentationItem item in rep.Items) { Entity entity = getEntityFromIfcRepresentationItem(item, viewportLayout1, entityTrs); if (entity != null) { entityList.Add(entity); } } if (entityList.Count > 1) { Block b = new Block(); foreach (Entity e in entityList) { b.Entities.Add(e); } viewportLayout1.Blocks.Add("Representation " + rep.Index.ToString(), b); BlockReference br = new IfcBlockReference("Representation " + rep.Index.ToString()); br.ColorMethod = colorMethodType.byParent; return(br); //return new IfcBlockReference("Representation " + rep.Index.ToString()); } else if (entityList.Count == 0) { return(null); } return(entityList[0]); }
public void CreateProductIfcTest() { // === create request string projectName = "test project"; string projectDescription = "project for test purposes"; Project project = new Project.Builder().withName(projectName) .withDescription(projectDescription) .build(); string personGivenName = "Cedric"; string personFamilyName = "Mélange"; string personIdentifier = "cmela"; Person person = new Person.Builder().withGivenName(personGivenName) .withFamilyName(personFamilyName) .withIdentifier(personIdentifier) .build(); string organizationName = "EC Life"; string organizationDescription = "EC Life - for an easy, economical and ecological life"; string organizationIdentifier = "ECL"; Organization organization = new Organization.Builder().withName(organizationName) .withDescription(organizationDescription) .withIdentifier(organizationIdentifier) .build(); string applicationName = "ECL IfcCreator"; string applicationVersion = "1.0"; string applicationIdentifier = "IfcCreator"; Application application = new Application.Builder().withName(applicationName) .withVersion(applicationVersion) .withIdentifier(applicationIdentifier) .withOrganization(new Organization.Builder().build()) .build(); OwnerHistory owner = new OwnerHistory.Builder().withPerson(person) .withOrganization(organization) .withApllication(application) .build(); string productName = "test product"; string productDescription = "product for test purposes"; string constructionString = "SHAPE({POLYLINE2D([[0,0],[0,1],[1,1],[1,0]])}).EXTRUDE(1)"; var material0 = new Material.Builder().withName("material0") .withColor(new ColorRGBa(1, 0, 0, 1)) .withRoughness(0) .isMetal() .build(); var material1 = new Material.Builder().withName("material1") .withColor(new ColorRGBa(0, 0, 1, 1)) .withRoughness(1) .isDielectric() .build(); RepresentationItem representationItem0 = new RepresentationItem.Builder() .withConstructionString(constructionString) .withMaterial(material0.id) .build(); var rotationQ = new Quaternion(); rotationQ.SetFromEuler(new double[] { 90, 90, 90 }); RepresentationItem representationItem1 = new RepresentationItem.Builder() .withConstructionString(constructionString) .withTransformation(new Transformation.Builder() .withTranslation(new double[] { 2, 0, 0 }) .withRotation(rotationQ.ToArray()) .build()) .withMaterial(material1.id) .build(); Representation representation = new Representation.Builder().AddRepresentationItem(representationItem0) .AddRepresentationItem(representationItem1) .addMaterial(material0) .addMaterial(material1) .build(); Product product = new Product.Builder().withName(productName) .withDescription(productDescription) .withType(ProductType.PROXY) .addRepresenation(representation) .build(); IfcSchema schema = IfcSchema.IFC2X3; ProductIfcRequest request = new ProductIfcRequest.Builder().withProject(project) .withOwner(owner) .withProduct(product) .withSchema(schema) .build(); // === convert to IFC stream MemoryStream memStream = new MemoryStream(); IProductIfcCreator productIfcCreator = new ProductIfcCreator(); productIfcCreator.CreateProductIfc(request, memStream); // === write to IFC file using (FileStream fileStream = File.Create("./product_ifc_creator_test.ifc")) { memStream.WriteTo(fileStream); } // === parse IFC stream Serializer serializer = new StepSerializer(typeof(IfcProject), null, schema.ToString(), null, "ECL IfcCreator"); IfcProject parsedProject = (IfcProject)serializer.ReadObject(memStream); // === test values Assert.Equal(projectName, parsedProject.Name); Assert.Equal(projectDescription, parsedProject.Description); IfcOwnerHistory parsedowner = parsedProject.OwnerHistory; Assert.Equal(personGivenName, parsedowner.OwningUser.ThePerson.GivenName); Assert.Equal(personFamilyName, parsedowner.OwningUser.ThePerson.FamilyName); Assert.Equal(personIdentifier, parsedowner.OwningUser.ThePerson.Identification.Value.Value); Assert.Equal(organizationName, parsedowner.OwningUser.TheOrganization.Name); Assert.Equal(organizationDescription, parsedowner.OwningUser.TheOrganization.Description); Assert.Equal(applicationName, parsedowner.OwningApplication.ApplicationFullName); Assert.Equal(applicationVersion, parsedowner.OwningApplication.Version); Assert.Equal(applicationIdentifier, parsedowner.OwningApplication.ApplicationIdentifier.Value); IfcSite parsedSite = (IfcSite)GetItem(GetItem(parsedProject.IsDecomposedBy, 0).RelatedObjects, 0); Assert.Equal(personGivenName, parsedSite.OwnerHistory.OwningUser.ThePerson.GivenName); IfcBuilding parsedBuilding = (IfcBuilding)GetItem(GetItem(parsedSite.IsDecomposedBy, 0).RelatedObjects, 0); Assert.Equal(personGivenName, parsedBuilding.OwnerHistory.OwningUser.ThePerson.GivenName); IfcBuildingStorey parsedStorey = (IfcBuildingStorey)GetItem(GetItem(parsedBuilding.IsDecomposedBy, 0).RelatedObjects, 0); Assert.Equal(personGivenName, parsedStorey.OwnerHistory.OwningUser.ThePerson.GivenName); IfcProduct parsedProduct = (IfcProduct)GetItem(GetItem(parsedStorey.ContainsElements, 0).RelatedElements, 0); Assert.Equal(personGivenName, parsedProduct.OwnerHistory.OwningUser.ThePerson.GivenName); Assert.Equal(productName, parsedProduct.Name); Assert.Equal(productDescription, parsedProduct.Description); Assert.Equal(1, parsedProduct.Representation.Representations.Count); IfcRepresentation parsedShapeRepresentation = GetItem(parsedProduct.Representation.Representations, 0); Assert.Equal("Body", parsedShapeRepresentation.RepresentationIdentifier); Assert.Equal("SolidModel", parsedShapeRepresentation.RepresentationType); Assert.Equal(2, parsedShapeRepresentation.Items.Count); Assert.IsType <IfcExtrudedAreaSolid>(GetItem(parsedShapeRepresentation.Items, 0)); Assert.IsType <IfcExtrudedAreaSolid>(GetItem(parsedShapeRepresentation.Items, 1)); var parsedItem0 = (IfcExtrudedAreaSolid)GetItem(parsedShapeRepresentation.Items, 0); Assert.Equal(1, parsedItem0.StyledByItem.Count); var StyledItem0 = GetItem(parsedItem0.StyledByItem, 0); Assert.Equal("material0", ((IfcSurfaceStyle)GetItem(StyledItem0.Styles, 0)).Name); var parsedItem1 = (IfcExtrudedAreaSolid)GetItem(parsedShapeRepresentation.Items, 1); Assert.Equal(2, parsedItem1.Position.Location.Coordinates[0].Value); Assert.Equal(0, parsedItem1.Position.Location.Coordinates[1].Value); Assert.Equal(0, parsedItem1.Position.Location.Coordinates[2].Value); Assert.Equal(1, parsedItem1.Position.Axis.DirectionRatios[0].Value, 5); Assert.Equal(0, parsedItem1.Position.Axis.DirectionRatios[1].Value, 5); Assert.Equal(0, parsedItem1.Position.Axis.DirectionRatios[2].Value, 5); Assert.Equal(0, parsedItem1.Position.RefDirection.DirectionRatios[0].Value, 5); Assert.Equal(0, parsedItem1.Position.RefDirection.DirectionRatios[1].Value, 5); Assert.Equal(1, parsedItem1.Position.RefDirection.DirectionRatios[2].Value, 5); Assert.Equal(1, parsedItem0.StyledByItem.Count); var StyledItem1 = GetItem(parsedItem1.StyledByItem, 0); Assert.Equal("material1", ((IfcSurfaceStyle)GetItem(StyledItem1.Styles, 0)).Name); }
/***************************************************/ /**** Public Methods ****/ /***************************************************/ protected override IEnumerable <IBHoMObject> Read(IRequest request, ActionConfig actionConfig = null) { if (request == null) { BH.Engine.Reflection.Compute.RecordError("The request is null, pull failed."); return(new List <IBHoMObject>()); } // Get the toolkit-specific PullConfig IfcPullConfig config = actionConfig as IfcPullConfig; if (config == null) { config = new IfcPullConfig(); BH.Engine.Reflection.Compute.RecordNote("Config has not been specified, default config is used."); } // Get the settings IfcSettings settings = this.IFCSettings.DefaultIfNull(); // Get the discipline coming from the request/PullConfig Discipline?requestDiscipline = request.Discipline(config.Discipline); if (requestDiscipline == null) { BH.Engine.Reflection.Compute.RecordError("Conflicting disciplines have been detected."); return(new List <IBHoMObject>()); } Discipline discipline = requestDiscipline.Value; // If instructed to pull mesh representations, the below variable will be assigned List <XbimShapeInstance> shapeInstances = null; if (config.PullMeshes) { if (m_3DContext == null) { m_3DContext = new Xbim3DModelContext(m_LoadedModel); m_3DContext.CreateContext(); } shapeInstances = m_3DContext.ShapeInstances().ToList(); } List <IBHoMObject> result = new List <IBHoMObject>(); foreach (var entity in m_LoadedModel.IIfcEntities(request)) { IIfcProduct element = entity as IIfcProduct; if (element == null) { continue; } IEnumerable <IBHoMObject> converted = element.IFromIfc(discipline, settings); // Pull mesh representations if requested in PullConfig if (shapeInstances != null) { List <Mesh> meshes = shapeInstances.Where(x => x.IfcProductLabel == element.EntityLabel).SelectMany(x => x.Meshes(m_3DContext)).ToList(); IfcRepresentation representation = new IfcRepresentation(meshes); foreach (IBHoMObject obj in converted) { obj.Fragments.Add(representation); } } result.AddRange(converted); } return(result); }
public IfcRepresentationMap(IfcAxis2Placement __MappingOrigin, IfcRepresentation __MappedRepresentation) { this._MappingOrigin = __MappingOrigin; this._MappedRepresentation = __MappedRepresentation; }