/******************************************************************************** * * * This file is part of IfcOpenShell. * * * * IfcOpenShell is free software: you can redistribute it and/or modify * * it under the terms of the Lesser GNU General Public License as published by * * the Free Software Foundation, either version 3.0 of the License, or * * (at your option) any later version. * * * * IfcOpenShell is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * Lesser GNU General Public License for more details. * * * * You should have received a copy of the Lesser GNU General Public License * * along with this program. If not, see . * * * ********************************************************************************/ /******************************************************************************** * * * This class is a subclass of the regular IfcFile class that implements * * several convenience functions for creating geometrical representations and * * spatial containers. * * * ********************************************************************************/ #include "IfcHierarchyHelper.h" #include using namespace std::string_literals; template typename Schema::IfcAxis2Placement3D IfcHierarchyHelper::addPlacement3d( double ox, double oy, double oz, double zx, double zy, double zz, double xx, double xy, double xz) { auto x = addTriplet(xx, xy, xz); auto z = addTriplet(zx, zy, zz); auto o = addTriplet(ox, oy, oz); auto p3d = create(); p3d.setLocation(o); p3d.setAxis(z); p3d.setRefDirection(x); return p3d; } template typename Schema::IfcAxis2Placement2D IfcHierarchyHelper::addPlacement2d( double ox, double oy, double xx, double xy) { auto x = addDoublet(xx, xy); auto o = addDoublet(ox, oy); auto p2d = create(); p2d.setLocation(o); p2d.setRefDirection(x); return p2d; } template typename Schema::IfcLocalPlacement IfcHierarchyHelper::addLocalPlacement(typename Schema::IfcObjectPlacement parent, double ox, double oy, double oz, double zx, double zy, double zz, double xx, double xy, double xz) { auto local_placement = create(); if (parent) { local_placement.setPlacementRelTo(parent); } local_placement.setRelativePlacement(addPlacement3d(ox, oy, oz, zx, zy, zz, xx, xy, xz)); return local_placement; } template typename Schema::IfcOwnerHistory IfcHierarchyHelper::addOwnerHistory() { typename Schema::IfcPerson person = create(); #ifdef HAS_SCHEMA_2x3 if constexpr (std::is_same_v) { person.setId(""); } else #endif { person.setIdentification(""); } auto organization = create(); organization.setName("IfcOpenShell"); auto person_and_org = create(); person_and_org.setThePerson(person); person_and_org.setTheOrganization(organization); auto application = create(); application.setApplicationDeveloper(organization); application.setVersion(IFCOPENSHELL_VERSION); application.setApplicationFullName("IfcOpenShell"); application.setApplicationIdentifier("IfcOpenShell"); int timestamp = (int)time(0); auto owner_hist = create(); owner_hist.setOwningUser(person_and_org); owner_hist.setOwningApplication(application); owner_hist.setChangeAction(Schema::IfcChangeActionEnum::IfcChangeAction_ADDED); owner_hist.setLastModifiedDate(timestamp); owner_hist.setLastModifyingUser(person_and_org); owner_hist.setLastModifyingApplication(application); owner_hist.setCreationDate(timestamp); return owner_hist; } template typename Schema::IfcProject IfcHierarchyHelper::addProject(typename Schema::IfcOwnerHistory owner_hist) { std::vector rep_contexts; auto dimexp = create(); dimexp.setLengthExponent(0); dimexp.setMassExponent(0); dimexp.setTimeExponent(0); dimexp.setElectricCurrentExponent(0); dimexp.setThermodynamicTemperatureExponent(0); dimexp.setAmountOfSubstanceExponent(0); dimexp.setLuminousIntensityExponent(0); auto unit1 = create(); unit1.setUnitType(Schema::IfcUnitEnum::IfcUnit_LENGTHUNIT); unit1.setPrefix(Schema::IfcSIPrefix::IfcSIPrefix_MILLI); unit1.setName(Schema::IfcSIUnitName::IfcSIUnitName_METRE); auto unit2a = create(); unit2a.setUnitType(Schema::IfcUnitEnum::IfcUnit_PLANEANGLEUNIT); unit2a.setName(Schema::IfcSIUnitName::IfcSIUnitName_RADIAN); auto unit2b = create(); auto measure = create(); measure.set_attribute_value(0, 0.01745329251); unit2b.setValueComponent(measure); unit2b.setUnitComponent(unit2a); auto unit2 = create(); unit2.setDimensions(dimexp); unit2.setUnitType(Schema::IfcUnitEnum::IfcUnit_PLANEANGLEUNIT); unit2.setName("Degrees"); unit2.setConversionFactor(unit2b); std::vector units = {unit1, unit2}; auto unit_assignment = create(); unit_assignment.setUnits(units); auto project = create(); project.setGlobalId(IfcParse::IfcGlobalId()); project.setOwnerHistory(owner_hist ? owner_hist : addOwnerHistory()); project.setRepresentationContexts(rep_contexts); project.setUnitsInContext(unit_assignment); return project; } template void IfcHierarchyHelper::relatePlacements(typename Schema::IfcProduct parent, typename Schema::IfcProduct product) { typename Schema::IfcObjectPlacement place = product.ObjectPlacement(); if (place) { if (auto local_place = place.template as()) { if (parent.ObjectPlacement()) { if (local_place != parent.ObjectPlacement()) { local_place.setPlacementRelTo(parent.ObjectPlacement()); } else { Logger::Notice("Placement cannot be relative to self"); } } } } } template typename Schema::IfcSite IfcHierarchyHelper::addSite(typename Schema::IfcProject proj, typename Schema::IfcOwnerHistory owner_hist) { if (!owner_hist) { owner_hist = getSingle(); } if (!owner_hist) { owner_hist = addOwnerHistory(); } if (!proj) { proj = getSingle(); } if (!proj) { proj = addProject(owner_hist); } auto site = create(); site.setGlobalId(IfcParse::IfcGlobalId()); site.setOwnerHistory(owner_hist); site.setObjectPlacement(addLocalPlacement()); site.setCompositionType(Schema::IfcElementCompositionEnum::IfcElementComposition_ELEMENT); addRelatedObject(proj, site, owner_hist); return site; } template typename Schema::IfcBuilding IfcHierarchyHelper::addBuilding(typename Schema::IfcSite site, typename Schema::IfcOwnerHistory owner_hist) { if (!owner_hist) { owner_hist = getSingle(); } if (!owner_hist) { owner_hist = addOwnerHistory(); } if (!site) { site = getSingle(); } if (!site) { site = addSite(typename Schema::IfcProject{}, owner_hist); } auto building = create(); building.setGlobalId(IfcParse::IfcGlobalId()); building.setOwnerHistory(owner_hist); building.setObjectPlacement(addLocalPlacement()); building.setCompositionType(Schema::IfcElementCompositionEnum::IfcElementComposition_ELEMENT); addRelatedObject(site, building, owner_hist); relatePlacements(site, building); return building; } template typename Schema::IfcBuildingStorey IfcHierarchyHelper::addBuildingStorey(typename Schema::IfcBuilding building, typename Schema::IfcOwnerHistory owner_hist) { if (!owner_hist) { owner_hist = getSingle(); } if (!owner_hist) { owner_hist = addOwnerHistory(); } if (!building) { building = getSingle(); } if (!building) { building = addBuilding(typename Schema::IfcSite{}, owner_hist); } auto storey = create(); storey.setGlobalId(IfcParse::IfcGlobalId()); storey.setOwnerHistory(owner_hist); storey.setObjectPlacement(addLocalPlacement()); storey.setCompositionType(Schema::IfcElementCompositionEnum::IfcElementComposition_ELEMENT); addRelatedObject(building, storey, owner_hist); relatePlacements(building, storey); return storey; } template typename Schema::IfcBuildingStorey IfcHierarchyHelper::addBuildingProduct(typename Schema::IfcProduct product, typename Schema::IfcBuildingStorey storey, typename Schema::IfcOwnerHistory owner_hist) { if (!owner_hist) { owner_hist = getSingle(); } if (!owner_hist) { owner_hist = addOwnerHistory(); } if (!storey) { storey = getSingle(); } if (!storey) { storey = addBuildingStorey(typename Schema::IfcBuilding{}, owner_hist); } // CV-2x3-158: Don't add decompositions directly to a building storey const bool is_decomposition = !product.Decomposes().empty(); if (!is_decomposition) { addRelatedObject(storey, product, owner_hist); relatePlacements(storey, product); } return storey; } template void IfcHierarchyHelper::addExtrudedPolyline(typename Schema::IfcShapeRepresentation rep, const std::vector>& points, double h, typename Schema::IfcAxis2Placement2D /*place1*/, typename Schema::IfcAxis2Placement3D place2, typename Schema::IfcDirection dir, typename Schema::IfcRepresentationContext /*context*/) { std::vector cartesian_points; for (auto& i : points) { cartesian_points.push_back(addDoublet(i.first, i.second)); } if (!cartesian_points.empty()) { cartesian_points.push_back(cartesian_points.front()); } auto line = create(); line.setPoints(cartesian_points); auto profile = create(); profile.setProfileType(Schema::IfcProfileTypeEnum::IfcProfileType_AREA); profile.setOuterCurve(line); auto solid = create(); solid.setSweptArea(profile); solid.setPosition(place2 ? place2 : addPlacement3d()); solid.setExtrudedDirection(dir ? dir : addTriplet(0, 0, 1)); solid.setDepth(h); std::vector items; try { auto existing_items = rep.Items(); items.insert(items.end(), existing_items.begin(), existing_items.end()); } catch (...) { // ignore } items.push_back(solid); rep.setItems(items); } template typename Schema::IfcProductDefinitionShape IfcHierarchyHelper::addExtrudedPolyline(const std::vector>& points, double h, typename Schema::IfcAxis2Placement2D place, typename Schema::IfcAxis2Placement3D place2, typename Schema::IfcDirection dir, typename Schema::IfcRepresentationContext context) { auto rep = create(); rep.setContextOfItems(context ? context : getRepresentationContext("Model")); rep.setRepresentationIdentifier(std::string("Body")); rep.setRepresentationType(std::string("SweptSolid")); rep.setItems(std::vector{}); auto shape = create(); shape.setRepresentations(std::vector{rep}); addExtrudedPolyline(rep, points, h, place, place2, dir, context); return shape; } template void IfcHierarchyHelper::addBox(typename Schema::IfcShapeRepresentation rep, double w, double d, double h, typename Schema::IfcAxis2Placement2D place, typename Schema::IfcAxis2Placement3D place2, typename Schema::IfcDirection dir, typename Schema::IfcRepresentationContext context) { std::vector> points; points.push_back(std::make_pair(-w / 2, -d / 2)); points.push_back(std::make_pair(w / 2, -d / 2)); points.push_back(std::make_pair(w / 2, d / 2)); points.push_back(std::make_pair(-w / 2, d / 2)); // The call to addExtrudedPolyline() closes the polyline addExtrudedPolyline(rep, points, h, place, place2, dir, context); } template void IfcHierarchyHelper::addAxis( typename Schema::IfcShapeRepresentation rep, double l, typename Schema::IfcRepresentationContext /*context*/) { auto p1 = addDoublet(-l / 2., 0.); auto p2 = addDoublet(+l / 2., 0.); std::vector pts{p1, p2}; auto poly = create(); poly.setPoints(pts); auto items = rep.Items(); items.push_back(poly); rep.setItems(items); } template typename Schema::IfcProductDefinitionShape IfcHierarchyHelper::addBox(double w, double d, double h, typename Schema::IfcAxis2Placement2D place, typename Schema::IfcAxis2Placement3D place2, typename Schema::IfcDirection dir, typename Schema::IfcRepresentationContext context) { typename Schema::IfcShapeRepresentation rep = create(); rep.setContextOfItems(context ? context : getRepresentationContext("Model")); rep.setRepresentationIdentifier(std::string("Body")); rep.setRepresentationType(std::string("SweptSolid")); rep.setItems(std::vector{}); auto shape = create(); shape.setRepresentations(std::vector{rep}); addBox(rep, w, d, h, place, place2, dir, context); return shape; } template typename Schema::IfcProductDefinitionShape IfcHierarchyHelper::addAxisBox( double w, double d, double h, typename Schema::IfcRepresentationContext context) { auto body_rep = create(); body_rep.setContextOfItems(context ? context : getRepresentationContext("Model")); body_rep.setRepresentationIdentifier(std::string("Body")); body_rep.setRepresentationType(std::string("SweptSolid")); body_rep.setItems(std::vector{}); auto axis_rep = create(); axis_rep.setContextOfItems(context ? context : getRepresentationContext("Plan")); axis_rep.setRepresentationIdentifier(std::string("Axis")); axis_rep.setRepresentationType(std::string("Curve2D")); axis_rep.setItems(std::vector{}); auto shape = create(); shape.setRepresentations(std::vector{axis_rep, body_rep}); addBox(body_rep, w, d, h, typename Schema::IfcAxis2Placement2D{}, typename Schema::IfcAxis2Placement3D{}, typename Schema::IfcDirection{}, context); addAxis(axis_rep, w); return shape; } template void IfcHierarchyHelper::clipRepresentation(typename Schema::IfcProductRepresentation shape, typename Schema::IfcAxis2Placement3D place, bool agree) { auto reps = shape.Representations(); for (auto& rep : reps) { clipRepresentation(rep, place, agree); } } template void IfcHierarchyHelper::clipRepresentation(typename Schema::IfcRepresentation rep, typename Schema::IfcAxis2Placement3D place, bool agree) { if (!rep.RepresentationIdentifier() || *rep.RepresentationIdentifier() != "Body") { return; } auto plane = create(); plane.setPosition(place); auto half_space = create(); half_space.setBaseSurface(plane); half_space.setAgreementFlag(agree); rep.setRepresentationType("Clipping"s); auto items = rep.Items(); decltype(items) new_items; for (auto& item : items) { if (auto bop = item.template as()) { auto clip = create(); clip.setOperator(Schema::IfcBooleanOperator::IfcBooleanOperator_DIFFERENCE); clip.setFirstOperand(bop); clip.setSecondOperand(half_space); new_items.push_back(clip); } } rep.setItems(new_items); } template typename Schema::IfcSurfaceStyle getSurfaceStyle(IfcHierarchyHelper& file, double r, double g, double b, double a = 1.0) { auto colour = file.template create(); colour.setRed(r); colour.setGreen(g); colour.setBlue(b); auto rendering = file.template create(); rendering.setSurfaceColour(colour); if (a != 1.0) { rendering.setTransparency(1.0 - a); } rendering.setReflectanceMethod(Schema::IfcReflectanceMethodEnum::IfcReflectanceMethod_FLAT); auto surface_style = file.template create(); surface_style.setSide(Schema::IfcSurfaceSide::IfcSurfaceSide_BOTH); surface_style.setStyles(std::vector{rendering}); return surface_style; } template typename Schema::IfcPresentationStyleAssignment addStyleAssignment_2x3(IfcHierarchyHelper& file, double r, double g, double b, double a = 1.0) { auto surface_style = getSurfaceStyle(file, r, g, b, a); auto style_assignment = file.template create(); style_assignment.setStyles(std::vector{surface_style}); return style_assignment; } template typename Schema::IfcPresentationStyle addStyleAssignment_4x3(IfcHierarchyHelper& file, double r, double g, double b, double a = 1.0) { return getSurfaceStyle(file, r, g, b, a); } template typename Schema::IfcPresentationStyleAssignment setSurfaceColour_2x3(IfcHierarchyHelper& file, typename Schema::IfcProductRepresentation shape, double r, double g, double b, double a) { typename Schema::IfcPresentationStyleAssignment style_assignment = addStyleAssignment_2x3(file, r, g, b, a); setSurfaceColour_2x3(file, shape, style_assignment); return style_assignment; } template typename Schema::IfcPresentationStyle setSurfaceColour_4x3(IfcHierarchyHelper& file, typename Schema::IfcProductRepresentation shape, double r, double g, double b, double a) { typename Schema::IfcPresentationStyle style_assignment = addStyleAssignment_4x3(file, r, g, b, a); setSurfaceColour_4x3(file, shape, style_assignment); return style_assignment; } template typename Schema::IfcPresentationStyleAssignment setSurfaceColour_2x3(IfcHierarchyHelper& file, typename Schema::IfcRepresentation shape, double r, double g, double b, double a) { typename Schema::IfcPresentationStyleAssignment style_assignment = addStyleAssignment_2x3(file, r, g, b, a); setSurfaceColour_2x3(file, shape, style_assignment); return style_assignment; } template typename Schema::IfcPresentationStyle setSurfaceColour_4x3(IfcHierarchyHelper& file, typename Schema::IfcRepresentation shape, double r, double g, double b, double a) { typename Schema::IfcPresentationStyle style_assignment = addStyleAssignment_4x3(file, r, g, b, a); setSurfaceColour_4x3(file, shape, style_assignment); return style_assignment; } template void setSurfaceColour_2x3(IfcHierarchyHelper& file, typename Schema::IfcProductRepresentation shape, typename Schema::IfcPresentationStyleAssignment style_assignment) { auto reps = shape.Representations(); for (auto& rep : reps) { setSurfaceColour_2x3(file, rep, style_assignment); } } template void setSurfaceColour_4x3(IfcHierarchyHelper& file, typename Schema::IfcProductRepresentation shape, typename Schema::IfcPresentationStyle style) { auto reps = shape.Representations(); for (auto& rep : reps) { setSurfaceColour_4x3(file, rep, style); } } #ifdef HAS_SCHEMA_2x3 Ifc2x3::IfcStyledItem create_styled_item(IfcParse::IfcFile* file, const Ifc2x3::IfcRepresentationItem& item, const Ifc2x3::IfcPresentationStyleAssignment& style_assignment) { auto sitem = file->create(); sitem.setItem(item); sitem.setStyles(std::vector{style_assignment}); return sitem; } #endif #ifdef HAS_SCHEMA_4 Ifc4::IfcStyledItem create_styled_item(IfcParse::IfcFile* file, Ifc4::IfcRepresentationItem item, Ifc4::IfcPresentationStyleAssignment style_assignment) { auto sitem = file->create(); sitem.setItem(item); sitem.setStyles(std::vector{style_assignment}); return sitem; } #endif #ifdef HAS_SCHEMA_4x1 Ifc4x1::IfcStyledItem create_styled_item(IfcParse::IfcFile* file, const Ifc4x1::IfcRepresentationItem& item, const Ifc4x1::IfcPresentationStyleAssignment& style_assignment) { auto sitem = file->create(); sitem.setItem(item); sitem.setStyles(std::vector{style_assignment}); return sitem; } #endif #ifdef HAS_SCHEMA_4x2 Ifc4x2::IfcStyledItem create_styled_item(IfcParse::IfcFile* file, const Ifc4x2::IfcRepresentationItem& item, const Ifc4x2::IfcPresentationStyleAssignment& style_assignment) { auto sitem = file->create(); sitem.setItem(item); sitem.setStyles(std::vector{style_assignment}); return sitem; } #endif #ifdef HAS_SCHEMA_4x3_rc1 Ifc4x3_rc1::IfcStyledItem create_styled_item(IfcParse::IfcFile* file, const Ifc4x3_rc1::IfcRepresentationItem& item, const Ifc4x3_rc1::IfcPresentationStyleAssignment& style_assignment) { auto sitem = file->create(); sitem.setItem(item); sitem.setStyles(std::vector{style_assignment}); return sitem; } #endif #ifdef HAS_SCHEMA_4x3_rc2 Ifc4x3_rc2::IfcStyledItem create_styled_item(IfcParse::IfcFile* file, const Ifc4x3_rc2::IfcRepresentationItem& item, const Ifc4x3_rc2::IfcPresentationStyleAssignment& style_assignment) { auto sitem = file->create(); sitem.setItem(item); sitem.setStyles(std::vector{style_assignment}); return sitem; } #endif #ifdef HAS_SCHEMA_4x3_rc3 Ifc4x3_rc3::IfcStyledItem create_styled_item(IfcParse::IfcFile* file, const Ifc4x3_rc3::IfcRepresentationItem& item, const Ifc4x3_rc3::IfcPresentationStyle& style) { auto sitem = file->create(); sitem.setItem(item); sitem.setStyles(std::vector{style}); return sitem; } #endif #ifdef HAS_SCHEMA_4x3_rc4 Ifc4x3_rc4::IfcStyledItem create_styled_item(IfcParse::IfcFile* file, const Ifc4x3_rc4::IfcRepresentationItem& item, const Ifc4x3_rc4::IfcPresentationStyle& style) { auto sitem = file->create(); sitem.setItem(item); sitem.setStyles(std::vector{style}); return sitem; } #endif #ifdef HAS_SCHEMA_4x3 Ifc4x3::IfcStyledItem create_styled_item(IfcParse::IfcFile* file, const Ifc4x3::IfcRepresentationItem& item, const Ifc4x3::IfcPresentationStyle& style) { auto sitem = file->create(); sitem.setItem(item); sitem.setStyles(std::vector{style}); return sitem; } #endif #ifdef HAS_SCHEMA_4x3_tc1 Ifc4x3_tc1::IfcStyledItem create_styled_item(IfcParse::IfcFile* file, const Ifc4x3_tc1::IfcRepresentationItem& item, const Ifc4x3_tc1::IfcPresentationStyle& style) { auto sitem = file.crefile->createate(); sitem.setItem(item); sitem.setStyles(std::vector{style}); return sitem; } #endif #ifdef HAS_SCHEMA_4x3_add1 Ifc4x3_add1::IfcStyledItem create_styled_item(IfcParse::IfcFile* file, const Ifc4x3_add1::IfcRepresentationItem& item, const Ifc4x3_add1::IfcPresentationStyle& style) { auto sitem = file->create(); sitem.setItem(item); sitem.setStyles(std::vector{style}); return sitem; } #endif #ifdef HAS_SCHEMA_4x3_add2 Ifc4x3_add2::IfcStyledItem create_styled_item(IfcParse::IfcFile* file, const Ifc4x3_add2::IfcRepresentationItem& item, const Ifc4x3_add2::IfcPresentationStyle& style) { auto sitem = file->create(); sitem.setItem(item); sitem.setStyles(std::vector{style}); return sitem; } #endif template void setSurfaceColour_2x3(IfcHierarchyHelper& file, typename Schema::IfcRepresentation rep, typename Schema::IfcPresentationStyleAssignment style_assignment) { auto items = rep.Items(); for (auto& item : items) { create_styled_item(&file, item, style_assignment); } } template void setSurfaceColour_4x3(IfcHierarchyHelper& file, typename Schema::IfcRepresentation rep, typename Schema::IfcPresentationStyle style) { // @todo is there still a difference here? auto items = rep.Items(); for (auto& item : items) { create_styled_item(&file, item, style); } } #ifdef HAS_SCHEMA_2x3 Ifc2x3::IfcPresentationStyleAssignment addStyleAssignment(IfcHierarchyHelper& file, double r, double g, double b, double a) { return addStyleAssignment_2x3(file, r, g, b, a); } Ifc2x3::IfcPresentationStyleAssignment setSurfaceColour(IfcHierarchyHelper& file, const Ifc2x3::IfcProductRepresentation& shape, double r, double g, double b, double a) { return setSurfaceColour_2x3(file, shape, r, g, b, a); } Ifc2x3::IfcPresentationStyleAssignment setSurfaceColour(IfcHierarchyHelper& file, const Ifc2x3::IfcRepresentation& shape, double r, double g, double b, double a) { return setSurfaceColour_2x3(file, shape, r, g, b, a); } void setSurfaceColour(IfcHierarchyHelper& file, const Ifc2x3::IfcProductRepresentation& shape, const Ifc2x3::IfcPresentationStyleAssignment& style_assignment) { setSurfaceColour_2x3(file, shape, style_assignment); } void setSurfaceColour(IfcHierarchyHelper& file, const Ifc2x3::IfcRepresentation& shape, const Ifc2x3::IfcPresentationStyleAssignment& style_assignment) { setSurfaceColour_2x3(file, shape, style_assignment); } #endif #ifdef HAS_SCHEMA_4 Ifc4::IfcPresentationStyleAssignment addStyleAssignment(IfcHierarchyHelper& file, double r, double g, double b, double a) { return addStyleAssignment_2x3(file, r, g, b, a); } Ifc4::IfcPresentationStyleAssignment setSurfaceColour(IfcHierarchyHelper& file, Ifc4::IfcProductRepresentation shape, double r, double g, double b, double a) { return setSurfaceColour_2x3(file, shape, r, g, b, a); } Ifc4::IfcPresentationStyleAssignment setSurfaceColour(IfcHierarchyHelper& file, Ifc4::IfcRepresentation shape, double r, double g, double b, double a) { return setSurfaceColour_2x3(file, shape, r, g, b, a); } void setSurfaceColour(IfcHierarchyHelper& file, Ifc4::IfcProductRepresentation shape, Ifc4::IfcPresentationStyleAssignment style_assignment) { setSurfaceColour_2x3(file, shape, style_assignment); } void setSurfaceColour(IfcHierarchyHelper& file, Ifc4::IfcRepresentation shape, Ifc4::IfcPresentationStyleAssignment style_assignment) { setSurfaceColour_2x3(file, shape, style_assignment); } #endif #ifdef HAS_SCHEMA_4x1 Ifc4x1::IfcPresentationStyleAssignment addStyleAssignment(IfcHierarchyHelper& file, double r, double g, double b, double a) { return addStyleAssignment_2x3(file, r, g, b, a); } Ifc4x1::IfcPresentationStyleAssignment setSurfaceColour(IfcHierarchyHelper& file, const Ifc4x1::IfcProductRepresentation& shape, double r, double g, double b, double a) { return setSurfaceColour_2x3(file, shape, r, g, b, a); } Ifc4x1::IfcPresentationStyleAssignment setSurfaceColour(IfcHierarchyHelper& file, const Ifc4x1::IfcRepresentation& shape, double r, double g, double b, double a) { return setSurfaceColour_2x3(file, shape, r, g, b, a); } void setSurfaceColour(IfcHierarchyHelper& file, const Ifc4x1::IfcProductRepresentation& shape, const Ifc4x1::IfcPresentationStyleAssignment& style_assignment) { setSurfaceColour_2x3(file, shape, style_assignment); } void setSurfaceColour(IfcHierarchyHelper& file, const Ifc4x1::IfcRepresentation& shape, const Ifc4x1::IfcPresentationStyleAssignment& style_assignment) { setSurfaceColour_2x3(file, shape, style_assignment); } #endif #ifdef HAS_SCHEMA_4x2 Ifc4x2::IfcPresentationStyleAssignment addStyleAssignment(IfcHierarchyHelper& file, double r, double g, double b, double a) { return addStyleAssignment_2x3(file, r, g, b, a); } Ifc4x2::IfcPresentationStyleAssignment setSurfaceColour(IfcHierarchyHelper& file, const Ifc4x2::IfcProductRepresentation& shape, double r, double g, double b, double a) { return setSurfaceColour_2x3(file, shape, r, g, b, a); } Ifc4x2::IfcPresentationStyleAssignment setSurfaceColour(IfcHierarchyHelper& file, const Ifc4x2::IfcRepresentation& shape, double r, double g, double b, double a) { return setSurfaceColour_2x3(file, shape, r, g, b, a); } void setSurfaceColour(IfcHierarchyHelper& file, const Ifc4x2::IfcProductRepresentation& shape, const Ifc4x2::IfcPresentationStyleAssignment& style_assignment) { setSurfaceColour_2x3(file, shape, style_assignment); } void setSurfaceColour(IfcHierarchyHelper& file, const Ifc4x2::IfcRepresentation& shape, const Ifc4x2::IfcPresentationStyleAssignment& style_assignment) { setSurfaceColour_2x3(file, shape, style_assignment); } #endif #ifdef HAS_SCHEMA_4x3_rc1 Ifc4x3_rc1::IfcPresentationStyleAssignment addStyleAssignment(IfcHierarchyHelper& file, double r, double g, double b, double a) { return addStyleAssignment_2x3(file, r, g, b, a); } Ifc4x3_rc1::IfcPresentationStyleAssignment setSurfaceColour(IfcHierarchyHelper& file, const Ifc4x3_rc1::IfcProductRepresentation& shape, double r, double g, double b, double a) { return setSurfaceColour_2x3(file, shape, r, g, b, a); } Ifc4x3_rc1::IfcPresentationStyleAssignment setSurfaceColour(IfcHierarchyHelper& file, const Ifc4x3_rc1::IfcRepresentation& shape, double r, double g, double b, double a) { return setSurfaceColour_2x3(file, shape, r, g, b, a); } void setSurfaceColour(IfcHierarchyHelper& file, const Ifc4x3_rc1::IfcProductRepresentation& shape, const Ifc4x3_rc1::IfcPresentationStyleAssignment& style_assignment) { setSurfaceColour_2x3(file, shape, style_assignment); } void setSurfaceColour(IfcHierarchyHelper& file, const Ifc4x3_rc1::IfcRepresentation& shape, const Ifc4x3_rc1::IfcPresentationStyleAssignment& style_assignment) { setSurfaceColour_2x3(file, shape, style_assignment); } #endif #ifdef HAS_SCHEMA_4x3_rc2 Ifc4x3_rc2::IfcPresentationStyleAssignment addStyleAssignment(IfcHierarchyHelper& file, double r, double g, double b, double a) { return addStyleAssignment_2x3(file, r, g, b, a); } Ifc4x3_rc2::IfcPresentationStyleAssignment setSurfaceColour(IfcHierarchyHelper& file, const Ifc4x3_rc2::IfcProductRepresentation& shape, double r, double g, double b, double a) { return setSurfaceColour_2x3(file, shape, r, g, b, a); } Ifc4x3_rc2::IfcPresentationStyleAssignment setSurfaceColour(IfcHierarchyHelper& file, const Ifc4x3_rc2::IfcRepresentation& shape, double r, double g, double b, double a) { return setSurfaceColour_2x3(file, shape, r, g, b, a); } void setSurfaceColour(IfcHierarchyHelper& file, const Ifc4x3_rc2::IfcProductRepresentation& shape, const Ifc4x3_rc2::IfcPresentationStyleAssignment& style_assignment) { setSurfaceColour_2x3(file, shape, style_assignment); } void setSurfaceColour(IfcHierarchyHelper& file, const Ifc4x3_rc2::IfcRepresentation& shape, const Ifc4x3_rc2::IfcPresentationStyleAssignment& style_assignment) { setSurfaceColour_2x3(file, shape, style_assignment); } #endif #ifdef HAS_SCHEMA_4x3_rc3 Ifc4x3_rc3::IfcPresentationStyle addStyleAssignment(IfcHierarchyHelper& file, double r, double g, double b, double a) { return addStyleAssignment_4x3(file, r, g, b, a); } Ifc4x3_rc3::IfcPresentationStyle setSurfaceColour(IfcHierarchyHelper& file, const Ifc4x3_rc3::IfcProductRepresentation& shape, double r, double g, double b, double a) { return setSurfaceColour_4x3(file, shape, r, g, b, a); } Ifc4x3_rc3::IfcPresentationStyle setSurfaceColour(IfcHierarchyHelper& file, const Ifc4x3_rc3::IfcRepresentation& shape, double r, double g, double b, double a) { return setSurfaceColour_4x3(file, shape, r, g, b, a); } void setSurfaceColour(IfcHierarchyHelper& file, const Ifc4x3_rc3::IfcProductRepresentation& shape, const Ifc4x3_rc3::IfcPresentationStyle& style) { setSurfaceColour_4x3(file, shape, style); } void setSurfaceColour(IfcHierarchyHelper& file, const Ifc4x3_rc3::IfcRepresentation& shape, const Ifc4x3_rc3::IfcPresentationStyle& style) { setSurfaceColour_4x3(file, shape, style); } #endif #ifdef HAS_SCHEMA_4x3_rc4 Ifc4x3_rc4::IfcPresentationStyle addStyleAssignment(IfcHierarchyHelper& file, double r, double g, double b, double a) { return addStyleAssignment_4x3(file, r, g, b, a); } Ifc4x3_rc4::IfcPresentationStyle setSurfaceColour(IfcHierarchyHelper& file, const Ifc4x3_rc4::IfcProductRepresentation& shape, double r, double g, double b, double a) { return setSurfaceColour_4x3(file, shape, r, g, b, a); } Ifc4x3_rc4::IfcPresentationStyle setSurfaceColour(IfcHierarchyHelper& file, const Ifc4x3_rc4::IfcRepresentation& shape, double r, double g, double b, double a) { return setSurfaceColour_4x3(file, shape, r, g, b, a); } void setSurfaceColour(IfcHierarchyHelper& file, const Ifc4x3_rc4::IfcProductRepresentation& shape, const Ifc4x3_rc4::IfcPresentationStyle& style) { setSurfaceColour_4x3(file, shape, style); } void setSurfaceColour(IfcHierarchyHelper& file, const Ifc4x3_rc4::IfcRepresentation& shape, const Ifc4x3_rc4::IfcPresentationStyle& style) { setSurfaceColour_4x3(file, shape, style); } #endif #ifdef HAS_SCHEMA_4x3 Ifc4x3::IfcPresentationStyle addStyleAssignment(IfcHierarchyHelper& file, double r, double g, double b, double a) { return addStyleAssignment_4x3(file, r, g, b, a); } Ifc4x3::IfcPresentationStyle setSurfaceColour(IfcHierarchyHelper& file, const Ifc4x3::IfcProductRepresentation& shape, double r, double g, double b, double a) { return setSurfaceColour_4x3(file, shape, r, g, b, a); } Ifc4x3::IfcPresentationStyle setSurfaceColour(IfcHierarchyHelper& file, const Ifc4x3::IfcRepresentation& shape, double r, double g, double b, double a) { return setSurfaceColour_4x3(file, shape, r, g, b, a); } void setSurfaceColour(IfcHierarchyHelper& file, const Ifc4x3::IfcProductRepresentation& shape, const Ifc4x3::IfcPresentationStyle& style) { setSurfaceColour_4x3(file, shape, style); } void setSurfaceColour(IfcHierarchyHelper& file, const Ifc4x3::IfcRepresentation& shape, const Ifc4x3::IfcPresentationStyle& style) { setSurfaceColour_4x3(file, shape, style); } #endif #ifdef HAS_SCHEMA_4x3_tc1 Ifc4x3_tc1::IfcPresentationStyle addStyleAssignment(IfcHierarchyHelper& file, double r, double g, double b, double a) { return addStyleAssignment_4x3(file, r, g, b, a); } Ifc4x3_tc1::IfcPresentationStyle setSurfaceColour(IfcHierarchyHelper& file, const Ifc4x3_tc1::IfcProductRepresentation& shape, double r, double g, double b, double a) { return setSurfaceColour_4x3(file, shape, r, g, b, a); } Ifc4x3_tc1::IfcPresentationStyle setSurfaceColour(IfcHierarchyHelper& file, const Ifc4x3_tc1::IfcRepresentation& shape, double r, double g, double b, double a) { return setSurfaceColour_4x3(file, shape, r, g, b, a); } void setSurfaceColour(IfcHierarchyHelper& file, const Ifc4x3_tc1::IfcProductRepresentation& shape, const Ifc4x3_tc1::IfcPresentationStyle& style) { setSurfaceColour_4x3(file, shape, style); } void setSurfaceColour(IfcHierarchyHelper& file, const Ifc4x3_tc1::IfcRepresentation& shape, const Ifc4x3_tc1::IfcPresentationStyle& style) { setSurfaceColour_4x3(file, shape, style); } #endif #ifdef HAS_SCHEMA_4x3_add1 Ifc4x3_add1::IfcPresentationStyle addStyleAssignment(IfcHierarchyHelper& file, double r, double g, double b, double a) { return addStyleAssignment_4x3(file, r, g, b, a); } Ifc4x3_add1::IfcPresentationStyle setSurfaceColour(IfcHierarchyHelper& file, const Ifc4x3_add1::IfcProductRepresentation& shape, double r, double g, double b, double a) { return setSurfaceColour_4x3(file, shape, r, g, b, a); } Ifc4x3_add1::IfcPresentationStyle setSurfaceColour(IfcHierarchyHelper& file, const Ifc4x3_add1::IfcRepresentation& shape, double r, double g, double b, double a) { return setSurfaceColour_4x3(file, shape, r, g, b, a); } void setSurfaceColour(IfcHierarchyHelper& file, const Ifc4x3_add1::IfcProductRepresentation& shape, const Ifc4x3_add1::IfcPresentationStyle& style) { setSurfaceColour_4x3(file, shape, style); } void setSurfaceColour(IfcHierarchyHelper& file, const Ifc4x3_add1::IfcRepresentation& shape, const Ifc4x3_add1::IfcPresentationStyle& style) { setSurfaceColour_4x3(file, shape, style); } #endif #ifdef HAS_SCHEMA_4x3_add2 Ifc4x3_add2::IfcPresentationStyle addStyleAssignment(IfcHierarchyHelper& file, double r, double g, double b, double a) { return addStyleAssignment_4x3(file, r, g, b, a); } Ifc4x3_add2::IfcPresentationStyle setSurfaceColour(IfcHierarchyHelper& file, const Ifc4x3_add2::IfcProductRepresentation& shape, double r, double g, double b, double a) { return setSurfaceColour_4x3(file, shape, r, g, b, a); } Ifc4x3_add2::IfcPresentationStyle setSurfaceColour(IfcHierarchyHelper& file, const Ifc4x3_add2::IfcRepresentation& shape, double r, double g, double b, double a) { return setSurfaceColour_4x3(file, shape, r, g, b, a); } void setSurfaceColour(IfcHierarchyHelper& file, const Ifc4x3_add2::IfcProductRepresentation& shape, const Ifc4x3_add2::IfcPresentationStyle& style) { setSurfaceColour_4x3(file, shape, style); } void setSurfaceColour(IfcHierarchyHelper& file, const Ifc4x3_add2::IfcRepresentation& shape, const Ifc4x3_add2::IfcPresentationStyle& style) { setSurfaceColour_4x3(file, shape, style); } #endif template typename Schema::IfcProductDefinitionShape IfcHierarchyHelper::addMappedItem( typename Schema::IfcShapeRepresentation rep, typename Schema::IfcCartesianTransformationOperator3D transform, typename Schema::IfcProductDefinitionShape def) { auto maps = rep.RepresentationMap(); typename Schema::IfcRepresentationMap map; if (maps.size() == 1) { map = maps.front(); } else { map = create(); map.setMappingOrigin(addPlacement3d()); map.setMappedRepresentation(rep); } std::vector representations; if (def) { representations = def.Representations(); } if (!transform) { transform = create(); transform.setLocalOrigin(addTriplet(0, 0, 0)); } auto item = create(); item.setMappingSource(map); item.setMappingTarget(transform); auto new_rep = create(); new_rep.setContextOfItems(rep.ContextOfItems()); new_rep.setRepresentationType(std::string("MappedRepresentation")); new_rep.setItems(std::vector{item}); if (rep.RepresentationIdentifier()) { new_rep.setRepresentationIdentifier(rep.RepresentationIdentifier()); } representations.push_back(new_rep); if (!def) { def = create(); def.setRepresentations(representations); } else { def.setRepresentations(representations); } return def; } template typename Schema::IfcProductDefinitionShape IfcHierarchyHelper::addMappedItem( std::vector& reps, typename Schema::IfcCartesianTransformationOperator3D transform) { typename Schema::IfcProductDefinitionShape def; for (auto& r : reps) { def = addMappedItem(r, transform, def); } return def; } template typename Schema::IfcShapeRepresentation IfcHierarchyHelper::addEmptyRepresentation(const std::string& repid, const std::string& reptype) { auto shape_rep = create(); shape_rep.setContextOfItems(getRepresentationContext(reptype == "Curve2D" ? "Plan" : "Model")); shape_rep.setRepresentationIdentifier(repid); shape_rep.setRepresentationType(reptype); shape_rep.setItems(std::vector{}); addEntity(shape_rep); return shape_rep; } namespace { template void push_back_to_maybe_optional(T& t, const U& u) { t.push_back(u); } // In IFC4 the IfcContext.RepresentationContexts has been made optional, so we need // some boiler plate to push back to a list that might be optional. template void push_back_to_maybe_optional(std::optional>& t, const U& u) { if (!t) { t.emplace(); } t->push_back(u); } } // namespace template typename Schema::IfcGeometricRepresentationContext IfcHierarchyHelper::getRepresentationContext(const std::string& s) { auto iter = contexts_.find(s); if (iter != contexts_.end()) { return iter->second; } auto project = getSingle(); if (!project) { project = addProject(); } auto project_contexts = project.RepresentationContexts(); auto context = create(); context.setContextIdentifier(s); context.setCoordinateSpaceDimension(3); context.setPrecision(1.e-5); context.setWorldCoordinateSystem(addPlacement3d()); context.setTrueNorth(addDoublet(0, 1)); push_back_to_maybe_optional(project_contexts, context); project.setRepresentationContexts(project_contexts); return contexts_[s] = context; } template typename Schema::IfcGeometricRepresentationSubContext IfcHierarchyHelper::getRepresentationSubContext(const std::string& ident, const std::string& type) { auto geometric_representation_context = getRepresentationContext(type); // creates the representation context if it doesn't already exist // search for a subcontext that matches the ContextIdentifier auto subcontexts = geometric_representation_context.HasSubContexts(); typename Schema::IfcGeometricRepresentationSubContext rep_subcontext; for (auto subcontext : subcontexts) { if (subcontext.ContextIdentifier().value_or("") == ident) { rep_subcontext = subcontext; break; // found it, break out of the loop } } if (!rep_subcontext) { // didn't find the subcontext, create it rep_subcontext = create(); rep_subcontext.setContextIdentifier(ident); rep_subcontext.setContextType(type); rep_subcontext.setParentContext(geometric_representation_context); rep_subcontext.setTargetView(Schema::IfcGeometricProjectionEnum::IfcGeometricProjection_MODEL_VIEW); } return rep_subcontext; } #ifdef HAS_SCHEMA_2x3 template IFC_PARSE_API class IfcHierarchyHelper; #endif #ifdef HAS_SCHEMA_4 template IFC_PARSE_API class IfcHierarchyHelper; #endif #ifdef HAS_SCHEMA_4x1 template IFC_PARSE_API class IfcHierarchyHelper; #endif #ifdef HAS_SCHEMA_4x2 template IFC_PARSE_API class IfcHierarchyHelper; #endif #ifdef HAS_SCHEMA_4x3_rc1 template IFC_PARSE_API class IfcHierarchyHelper; #endif #ifdef HAS_SCHEMA_4x3_rc2 template IFC_PARSE_API class IfcHierarchyHelper; #endif #ifdef HAS_SCHEMA_4x3_rc3 template IFC_PARSE_API class IfcHierarchyHelper; #endif #ifdef HAS_SCHEMA_4x3_rc4 template IFC_PARSE_API class IfcHierarchyHelper; #endif #ifdef HAS_SCHEMA_4x3 template IFC_PARSE_API class IfcHierarchyHelper; #endif #ifdef HAS_SCHEMA_4x3_tc1 template IFC_PARSE_API class IfcHierarchyHelper; #endif #ifdef HAS_SCHEMA_4x3_add1 template IFC_PARSE_API class IfcHierarchyHelper; #endif #ifdef HAS_SCHEMA_4x3_add2 template IFC_PARSE_API class IfcHierarchyHelper; #endif