|
| 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 | +int main(int argc, char** argv) { |
| 39 | + const char filename[] = "IfcCompositeProfileDef.ifc"; |
| 40 | + IfcHierarchyHelper file; |
| 41 | + file.filename(filename); |
| 42 | + |
| 43 | + double coords1[] = {100.0, 0.0}; |
| 44 | + double coords2[] = {200.0, 0.0}; |
| 45 | + double coords3[] = {300.0, 0.0}; |
| 46 | + |
| 47 | + IfcSchema::IfcProfileDef::list profiles (new IfcTemplatedEntityList<IfcSchema::IfcProfileDef>()); |
| 48 | + |
| 49 | + IfcSchema::IfcCartesianTransformationOperator2D* transform1 = new IfcSchema::IfcCartesianTransformationOperator2D(file.addDoublet<IfcSchema::IfcDirection>(1, 0), file.addDoublet<IfcSchema::IfcDirection>(0, -1), file.addDoublet<IfcSchema::IfcCartesianPoint>(40, 0), null); |
| 50 | + IfcSchema::IfcCartesianTransformationOperator2D* transform2 = new IfcSchema::IfcCartesianTransformationOperator2D(file.addDoublet<IfcSchema::IfcDirection>(0, -1), file.addDoublet<IfcSchema::IfcDirection>(1, 0), file.addDoublet<IfcSchema::IfcCartesianPoint>(40, 0), 0.3); |
| 51 | + |
| 52 | + IfcSchema::IfcProfileDef* p1 = new Ifc2x3::IfcIShapeProfileDef( |
| 53 | + IfcSchema::IfcProfileTypeEnum::IfcProfileType_AREA, |
| 54 | + null, file.addPlacement2d(), 25.0, 50.0, 5.0, 5.0, 2.0); |
| 55 | + |
| 56 | + IfcSchema::IfcProfileDef* p2 = new Ifc2x3::IfcLShapeProfileDef( |
| 57 | + IfcSchema::IfcProfileTypeEnum::IfcProfileType_AREA, |
| 58 | + null, file.addPlacement2d(), 50.0, 25.0, 5.0, 1.0, 2.0, 2.0, null, null); |
| 59 | + |
| 60 | + IfcSchema::IfcProfileDef* p3 = new Ifc2x3::IfcTShapeProfileDef( |
| 61 | + IfcSchema::IfcProfileTypeEnum::IfcProfileType_AREA, |
| 62 | + null, file.addPlacement2d(), 50.0, 40.0, 10.0, 10.0, 3.0, 2.0, 1.0, 2.0, 2.0, null); |
| 63 | + |
| 64 | + IfcSchema::IfcProfileDef* p4 = new Ifc2x3::IfcCShapeProfileDef( |
| 65 | + IfcSchema::IfcProfileTypeEnum::IfcProfileType_AREA, |
| 66 | + null, file.addPlacement2d(80.), 50.0, 25.0, 5.0, 10.0, 2.0, null); |
| 67 | + |
| 68 | + file.AddEntity(p2); |
| 69 | + file.AddEntity(p3); |
| 70 | + |
| 71 | + file.AddEntity(transform1); |
| 72 | + file.AddEntity(transform2); |
| 73 | + |
| 74 | + IfcSchema::IfcDerivedProfileDef* p5 = new IfcSchema::IfcDerivedProfileDef(IfcSchema::IfcProfileTypeEnum::IfcProfileType_AREA, null, p2, transform1, null); |
| 75 | + IfcSchema::IfcDerivedProfileDef* p6 = new IfcSchema::IfcDerivedProfileDef(IfcSchema::IfcProfileTypeEnum::IfcProfileType_AREA, null, p3, transform2, null); |
| 76 | + |
| 77 | + profiles->push(p1); |
| 78 | + profiles->push(p5); |
| 79 | + profiles->push(p6); |
| 80 | + profiles->push(p4); |
| 81 | + |
| 82 | + file.AddEntities(profiles->generalize()); |
| 83 | + |
| 84 | + IfcSchema::IfcCompositeProfileDef* composite = new IfcSchema::IfcCompositeProfileDef(IfcSchema::IfcProfileTypeEnum::IfcProfileType_AREA, S("IFC"), profiles, null); |
| 85 | + |
| 86 | + IfcSchema::IfcBuildingElementProxy* product = new IfcSchema::IfcBuildingElementProxy( |
| 87 | + guid(), 0, S("profile"), null, null, 0, 0, null, null); |
| 88 | + |
| 89 | + file.addBuildingProduct(product); |
| 90 | + |
| 91 | + product->setOwnerHistory(file.getSingle<IfcSchema::IfcOwnerHistory>()); |
| 92 | + |
| 93 | + product->setObjectPlacement(file.addLocalPlacement()); |
| 94 | + |
| 95 | + IfcSchema::IfcExtrudedAreaSolid* solid = new IfcSchema::IfcExtrudedAreaSolid(composite, |
| 96 | + file.addPlacement3d(), file.addTriplet<IfcSchema::IfcDirection>(0, 0, 1), 20.0); |
| 97 | + |
| 98 | + file.AddEntity(composite); |
| 99 | + file.AddEntity(solid); |
| 100 | + |
| 101 | + IfcSchema::IfcRepresentation::list reps (new IfcTemplatedEntityList<IfcSchema::IfcRepresentation>()); |
| 102 | + IfcSchema::IfcRepresentationItem::list items (new IfcTemplatedEntityList<IfcSchema::IfcRepresentationItem>()); |
| 103 | + |
| 104 | + items->push(solid); |
| 105 | + IfcSchema::IfcShapeRepresentation* rep = new IfcSchema::IfcShapeRepresentation( |
| 106 | + file.getSingle<IfcSchema::IfcRepresentationContext>(), S("Body"), S("SweptSolid"), items); |
| 107 | + reps->push(rep); |
| 108 | + |
| 109 | + IfcSchema::IfcProductDefinitionShape* shape = new IfcSchema::IfcProductDefinitionShape(0, 0, reps); |
| 110 | + file.AddEntity(rep); |
| 111 | + file.AddEntity(shape); |
| 112 | + |
| 113 | + product->setRepresentation(shape); |
| 114 | + |
| 115 | + file.getSingle<IfcSchema::IfcProject>()->setName("IfcCompositeProfileDef"); |
| 116 | + |
| 117 | + std::ofstream f(filename); |
| 118 | + f << file; |
| 119 | +} |
0 commit comments