|
| 1 | +/******************************************************************************** |
| 2 | + * * |
| 3 | + * This file is part of IfcOpenShell. * |
| 4 | + * * |
| 5 | + * IfcOpenShell is free software: you can redistribute it and/or modify * |
| 6 | + * it under the terms of the Lesser GNU General Public License as published by * |
| 7 | + * the Free Software Foundation, either version 3.0 of the License, or * |
| 8 | + * (at your option) any later version. * |
| 9 | + * * |
| 10 | + * IfcOpenShell is distributed in the hope that it will be useful, * |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 13 | + * Lesser GNU General Public License for more details. * |
| 14 | + * * |
| 15 | + * You should have received a copy of the Lesser GNU General Public License * |
| 16 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. * |
| 17 | + * * |
| 18 | + ********************************************************************************/ |
| 19 | + |
| 20 | +/******************************************************************************** |
| 21 | + * * |
| 22 | + * Example that generates extrusions of parameterized profiles. * |
| 23 | + * * |
| 24 | + ********************************************************************************/ |
| 25 | + |
| 26 | +#include <string> |
| 27 | +#include <iostream> |
| 28 | +#include <fstream> |
| 29 | + |
| 30 | +#include "../ifcparse/Ifc2x3.h" |
| 31 | +#include "../ifcparse/IfcUtil.h" |
| 32 | +#include "../ifcparse/IfcHierarchyHelper.h" |
| 33 | + |
| 34 | +typedef std::string S; |
| 35 | +typedef IfcWrite::IfcGuidHelper guid; |
| 36 | +boost::none_t const null = (static_cast<boost::none_t>(0)); |
| 37 | + |
| 38 | +void create_testcase_for(IfcSchema::IfcProfileDef::list profiles) { |
| 39 | + IfcSchema::IfcProfileDef* profile = *profiles->begin(); |
| 40 | + const std::string profile_type = IfcSchema::Type::ToString(profile->type()); |
| 41 | + const std::string filename = profile_type + ".ifc"; |
| 42 | + |
| 43 | + IfcHierarchyHelper file; |
| 44 | + file.filename(filename); |
| 45 | + |
| 46 | + int i = 0; |
| 47 | + for (IfcSchema::IfcProfileDef::it it = profiles->begin(); it != profiles->end(); ++it, ++i) { |
| 48 | + IfcSchema::IfcProfileDef* profile = *it; |
| 49 | + IfcSchema::IfcBuildingElementProxy* product = new IfcSchema::IfcBuildingElementProxy( |
| 50 | + guid(), 0, S("profile"), null, null, 0, 0, null, null); |
| 51 | + file.addBuildingProduct(product); |
| 52 | + file.getSingle<IfcSchema::IfcProject>()->setName(profile_type); |
| 53 | + product->setOwnerHistory(file.getSingle<IfcSchema::IfcOwnerHistory>()); |
| 54 | + |
| 55 | + product->setObjectPlacement(file.addLocalPlacement(100 * i)); |
| 56 | + |
| 57 | + if (profile->is(IfcSchema::Type::IfcParameterizedProfileDef)) { |
| 58 | + ((IfcSchema::IfcParameterizedProfileDef*) profile)->setPosition(file.addPlacement2d()); |
| 59 | + } |
| 60 | + |
| 61 | + IfcSchema::IfcExtrudedAreaSolid* solid = new IfcSchema::IfcExtrudedAreaSolid(profile, |
| 62 | + file.addPlacement3d(), file.addTriplet<IfcSchema::IfcDirection>(0, 0, 1), 20.0); |
| 63 | + |
| 64 | + file.AddEntity(profile); |
| 65 | + file.AddEntity(solid); |
| 66 | + |
| 67 | + IfcSchema::IfcRepresentation::list reps (new IfcTemplatedEntityList<IfcSchema::IfcRepresentation>()); |
| 68 | + IfcSchema::IfcRepresentationItem::list items (new IfcTemplatedEntityList<IfcSchema::IfcRepresentationItem>()); |
| 69 | + |
| 70 | + items->push(solid); |
| 71 | + IfcSchema::IfcShapeRepresentation* rep = new IfcSchema::IfcShapeRepresentation( |
| 72 | + file.getSingle<IfcSchema::IfcRepresentationContext>(), S("Body"), S("SweptSolid"), items); |
| 73 | + reps->push(rep); |
| 74 | + |
| 75 | + IfcSchema::IfcProductDefinitionShape* shape = new IfcSchema::IfcProductDefinitionShape(0, 0, reps); |
| 76 | + file.AddEntity(rep); |
| 77 | + file.AddEntity(shape); |
| 78 | + |
| 79 | + product->setRepresentation(shape); |
| 80 | + } |
| 81 | + |
| 82 | + std::ofstream f(filename.c_str()); |
| 83 | + f << file; |
| 84 | +} |
| 85 | + |
| 86 | +int main(int argc, char** argv) { |
| 87 | + { IfcSchema::IfcProfileDef::list profiles (new IfcTemplatedEntityList<IfcSchema::IfcProfileDef>()); |
| 88 | + profiles->push(new Ifc2x3::IfcUShapeProfileDef( |
| 89 | + IfcSchema::IfcProfileTypeEnum::IfcProfileType_AREA, |
| 90 | + null, 0, 50.0, 25.0, 5.0, 5.0, null, null, null, null)); |
| 91 | + profiles->push(new Ifc2x3::IfcUShapeProfileDef( |
| 92 | + IfcSchema::IfcProfileTypeEnum::IfcProfileType_AREA, |
| 93 | + null, 0, 50.0, 25.0, 5.0, 5.0, 2.0, 2.0, null, null)); |
| 94 | + profiles->push(new Ifc2x3::IfcUShapeProfileDef( |
| 95 | + IfcSchema::IfcProfileTypeEnum::IfcProfileType_AREA, |
| 96 | + null, 0, 50.0, 25.0, 5.0, 5.0, null, null, 0.1, null)); |
| 97 | + profiles->push(new Ifc2x3::IfcUShapeProfileDef( |
| 98 | + IfcSchema::IfcProfileTypeEnum::IfcProfileType_AREA, |
| 99 | + null, 0, 50.0, 25.0, 5.0, 5.0, 1.0, 3.0, 0.1, null)); |
| 100 | + create_testcase_for(profiles); } |
| 101 | + |
| 102 | + { IfcSchema::IfcProfileDef::list profiles (new IfcTemplatedEntityList<IfcSchema::IfcProfileDef>()); |
| 103 | + profiles->push(new Ifc2x3::IfcTShapeProfileDef( |
| 104 | + IfcSchema::IfcProfileTypeEnum::IfcProfileType_AREA, |
| 105 | + null, 0, 50.0, 25.0, 5.0, 5.0, null, null, null, null, null, null)); |
| 106 | + profiles->push(new Ifc2x3::IfcTShapeProfileDef( |
| 107 | + IfcSchema::IfcProfileTypeEnum::IfcProfileType_AREA, |
| 108 | + null, 0, 50.0, 25.0, 5.0, 5.0, 2.0, 2.0, 2.0, null, null, null)); |
| 109 | + profiles->push(new Ifc2x3::IfcTShapeProfileDef( |
| 110 | + IfcSchema::IfcProfileTypeEnum::IfcProfileType_AREA, |
| 111 | + null, 0, 50.0, 25.0, 5.0, 5.0, null, null, null, 0.1, 0.1, null)); |
| 112 | + profiles->push(new Ifc2x3::IfcTShapeProfileDef( |
| 113 | + IfcSchema::IfcProfileTypeEnum::IfcProfileType_AREA, |
| 114 | + null, 0, 50.0, 25.0, 5.0, 5.0, 1.0, 2.0, 3.0, 0.1, 0.2, null)); |
| 115 | + create_testcase_for(profiles); } |
| 116 | + |
| 117 | + { IfcSchema::IfcProfileDef::list profiles (new IfcTemplatedEntityList<IfcSchema::IfcProfileDef>()); |
| 118 | + profiles->push(new Ifc2x3::IfcZShapeProfileDef( |
| 119 | + IfcSchema::IfcProfileTypeEnum::IfcProfileType_AREA, |
| 120 | + null, 0, 50.0, 25.0, 5.0, 5.0, null, null)); |
| 121 | + profiles->push(new Ifc2x3::IfcZShapeProfileDef( |
| 122 | + IfcSchema::IfcProfileTypeEnum::IfcProfileType_AREA, |
| 123 | + null, 0, 50.0, 25.0, 5.0, 5.0, 2.0, 2.0)); |
| 124 | + create_testcase_for(profiles); } |
| 125 | + |
| 126 | + { IfcSchema::IfcProfileDef::list profiles (new IfcTemplatedEntityList<IfcSchema::IfcProfileDef>()); |
| 127 | + profiles->push(new Ifc2x3::IfcEllipseProfileDef( |
| 128 | + IfcSchema::IfcProfileTypeEnum::IfcProfileType_AREA, |
| 129 | + null, 0, 50.0, 25.0)); |
| 130 | + profiles->push(new Ifc2x3::IfcEllipseProfileDef( |
| 131 | + IfcSchema::IfcProfileTypeEnum::IfcProfileType_AREA, |
| 132 | + null, 0, 25.0, 50.0)); |
| 133 | + create_testcase_for(profiles); } |
| 134 | + |
| 135 | + { IfcSchema::IfcProfileDef::list profiles (new IfcTemplatedEntityList<IfcSchema::IfcProfileDef>()); |
| 136 | + profiles->push(new Ifc2x3::IfcIShapeProfileDef( |
| 137 | + IfcSchema::IfcProfileTypeEnum::IfcProfileType_AREA, |
| 138 | + null, 0, 25.0, 50.0, 5.0, 5.0, null)); |
| 139 | + profiles->push(new Ifc2x3::IfcIShapeProfileDef( |
| 140 | + IfcSchema::IfcProfileTypeEnum::IfcProfileType_AREA, |
| 141 | + null, 0, 25.0, 50.0, 5.0, 5.0, 2.0)); |
| 142 | + create_testcase_for(profiles); } |
| 143 | + |
| 144 | + { IfcSchema::IfcProfileDef::list profiles (new IfcTemplatedEntityList<IfcSchema::IfcProfileDef>()); |
| 145 | + profiles->push(new Ifc2x3::IfcLShapeProfileDef( |
| 146 | + IfcSchema::IfcProfileTypeEnum::IfcProfileType_AREA, |
| 147 | + null, 0, 50.0, 25.0, 5.0, null, null, null, null, null)); |
| 148 | + profiles->push(new Ifc2x3::IfcLShapeProfileDef( |
| 149 | + IfcSchema::IfcProfileTypeEnum::IfcProfileType_AREA, |
| 150 | + null, 0, 50.0, 25.0, 5.0, 2.0, 2.0, null, null, null)); |
| 151 | + profiles->push(new Ifc2x3::IfcLShapeProfileDef( |
| 152 | + IfcSchema::IfcProfileTypeEnum::IfcProfileType_AREA, |
| 153 | + null, 0, 50.0, 25.0, 5.0, null, null, 0.1, null, null)); |
| 154 | + profiles->push(new Ifc2x3::IfcLShapeProfileDef( |
| 155 | + IfcSchema::IfcProfileTypeEnum::IfcProfileType_AREA, |
| 156 | + null, 0, 50.0, 25.0, 5.0, 1.0, 2.0, 0.3, null, null)); |
| 157 | + create_testcase_for(profiles); } |
| 158 | + |
| 159 | + { IfcSchema::IfcProfileDef::list profiles (new IfcTemplatedEntityList<IfcSchema::IfcProfileDef>()); |
| 160 | + profiles->push(new Ifc2x3::IfcCShapeProfileDef( |
| 161 | + IfcSchema::IfcProfileTypeEnum::IfcProfileType_AREA, |
| 162 | + null, 0, 50.0, 25.0, 5.0, 10.0, null, null)); |
| 163 | + profiles->push(new Ifc2x3::IfcCShapeProfileDef( |
| 164 | + IfcSchema::IfcProfileTypeEnum::IfcProfileType_AREA, |
| 165 | + null, 0, 50.0, 25.0, 5.0, 10.0, 2.0, null)); |
| 166 | + create_testcase_for(profiles); } |
| 167 | + |
| 168 | + { IfcSchema::IfcProfileDef::list profiles (new IfcTemplatedEntityList<IfcSchema::IfcProfileDef>()); |
| 169 | + profiles->push(new Ifc2x3::IfcCircleProfileDef( |
| 170 | + IfcSchema::IfcProfileTypeEnum::IfcProfileType_AREA, |
| 171 | + null, 0, 25.0)); |
| 172 | + profiles->push(new Ifc2x3::IfcCircleHollowProfileDef( |
| 173 | + IfcSchema::IfcProfileTypeEnum::IfcProfileType_AREA, |
| 174 | + null, 0, 25.0, 5.0)); |
| 175 | + create_testcase_for(profiles); } |
| 176 | + |
| 177 | + { IfcSchema::IfcProfileDef::list profiles (new IfcTemplatedEntityList<IfcSchema::IfcProfileDef>()); |
| 178 | + profiles->push(new Ifc2x3::IfcRectangleProfileDef( |
| 179 | + IfcSchema::IfcProfileTypeEnum::IfcProfileType_AREA, |
| 180 | + null, 0, 50.0, 25.0)); |
| 181 | + profiles->push(new Ifc2x3::IfcRoundedRectangleProfileDef( |
| 182 | + IfcSchema::IfcProfileTypeEnum::IfcProfileType_AREA, |
| 183 | + null, 0, 50.0, 25.0, 5.0)); |
| 184 | + profiles->push(new Ifc2x3::IfcRectangleHollowProfileDef( |
| 185 | + IfcSchema::IfcProfileTypeEnum::IfcProfileType_AREA, |
| 186 | + null, 0, 50.0, 25.0, 5.0, null, null)); |
| 187 | + profiles->push(new Ifc2x3::IfcRectangleHollowProfileDef( |
| 188 | + IfcSchema::IfcProfileTypeEnum::IfcProfileType_AREA, |
| 189 | + null, 0, 50.0, 25.0, 5.0, 2.0, 4.0)); |
| 190 | + create_testcase_for(profiles); } |
| 191 | + |
| 192 | + { IfcSchema::IfcProfileDef::list profiles (new IfcTemplatedEntityList<IfcSchema::IfcProfileDef>()); |
| 193 | + profiles->push(new Ifc2x3::IfcTrapeziumProfileDef( |
| 194 | + IfcSchema::IfcProfileTypeEnum::IfcProfileType_AREA, |
| 195 | + null, 0, 50.0, 30.0, 25.0, 0.0)); |
| 196 | + profiles->push(new Ifc2x3::IfcTrapeziumProfileDef( |
| 197 | + IfcSchema::IfcProfileTypeEnum::IfcProfileType_AREA, |
| 198 | + null, 0, 50.0, 60.0, 25.0, -20.0)); |
| 199 | + profiles->push(new Ifc2x3::IfcTrapeziumProfileDef( |
| 200 | + IfcSchema::IfcProfileTypeEnum::IfcProfileType_AREA, |
| 201 | + null, 0, 50.0, 10.0, 25.0, 30.0)); |
| 202 | + create_testcase_for(profiles); } |
| 203 | +} |
0 commit comments