Examples and update virtual bases for new codegen

This commit is contained in:
Thomas Krijnen
2026-04-18 21:04:42 +02:00
parent 1cc93784cd
commit bccea6d932
3 changed files with 20 additions and 26 deletions
@@ -29,7 +29,6 @@
#include <fstream>
#include "../ifcparse/schemas/Ifc2x3.h"
#include "../ifcparse/IfcUtil.h"
#include "../ifcparse/hierarchy_helper.h"
typedef std::string S;
+15 -20
View File
@@ -23,15 +23,15 @@
* *
********************************************************************************/
#include "../ifcparse/Ifc4.h"
#include "../ifcparse/IfcUtil.h"
#include "../ifcparse/schemas/Ifc4.h"
#include "../ifcparse/hierarchy_helper.h"
#include "suzanne_geometry.h"
#include <fstream>
typedef std::string S;
typedef ifcopenshell::global_id guid;
boost::none_t const null = (static_cast<boost::none_t>(0));
template <typename T>
std::vector< std::vector<T> > create_vector_from_array(const T* arr, unsigned size) {
@@ -50,36 +50,31 @@ std::vector< std::vector<T> > create_vector_from_array(const T* arr, unsigned si
}
int main(int argc, char** argv) {
hierarchy_helper file;
hierarchy_helper<Ifc4> file;
IfcSchema::IfcBuildingElementProxy* product = new IfcSchema::IfcBuildingElementProxy(
guid(), 0, S("Blender's Suzanne"), null, null, 0, 0, null, null);
Ifc4::IfcBuildingElementProxy product = file.create<Ifc4::IfcBuildingElementProxy>().initialize(
guid(), std::nullopt, S("Blender's Suzanne"), std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt);
file.addBuildingProduct(product);
product->setOwnerHistory(file.getSingle<IfcSchema::IfcOwnerHistory>());
product.setOwnerHistory(file.getSingle<Ifc4::IfcOwnerHistory>());
product->setObjectPlacement(file.addLocalPlacement());
IfcSchema::IfcRepresentation::list::ptr reps (new IfcSchema::IfcRepresentation::list);
IfcSchema::IfcRepresentationItem::list::ptr items (new IfcSchema::IfcRepresentationItem::list);
product.setObjectPlacement(file.addLocalPlacement());
std::vector< std::vector< double > > vertices_vector = create_vector_from_array(vertices, sizeof(vertices) / sizeof(vertices[0]));
std::vector< std::vector< int > > indices_vector = create_vector_from_array(indices, sizeof(indices) / sizeof(indices[0]));
IfcSchema::IfcCartesianPointList3D* coordinates = new IfcSchema::IfcCartesianPointList3D(vertices_vector);
IfcSchema::IfcTriangulatedFaceSet* faceset = new IfcSchema::IfcTriangulatedFaceSet(coordinates, null, null, indices_vector, null);
Ifc4::IfcCartesianPointList3D coordinates = file.create<Ifc4::IfcCartesianPointList3D>().initialize(vertices_vector);
Ifc4::IfcTriangulatedFaceSet faceset = file.create<Ifc4::IfcTriangulatedFaceSet>().initialize(coordinates, std::nullopt, std::nullopt, indices_vector, std::nullopt);
items->push(faceset);
IfcSchema::IfcShapeRepresentation* rep = new IfcSchema::IfcShapeRepresentation(
file.getRepresentationContext("Model"), S("Body"), S("SurfaceModel"), items);
reps->push(rep);
Ifc4::IfcShapeRepresentation rep = file.create<Ifc4::IfcShapeRepresentation>().initialize(
file.getRepresentationContext("Model"), "Body", "SurfaceModel", {faceset});
IfcSchema::IfcProductDefinitionShape* shape = new IfcSchema::IfcProductDefinitionShape(0, 0, reps);
Ifc4::IfcProductDefinitionShape shape = file.create<Ifc4::IfcProductDefinitionShape>().initialize(std::nullopt, std::nullopt, {rep});
file.add_entity(shape);
product->setRepresentation(shape);
product.setRepresentation(shape);
const std::string filename = "tesselated_faceset.ifc";
file.header().file_name().name(filename);
file.header().file_name().setname(filename);
std::ofstream f(filename.c_str());
f << file;
}
+5 -5
View File
@@ -70,6 +70,7 @@ class IFC_PARSE_API Base {
}
Base() {};
Base(std::nullopt_t) noexcept : Base() {}
Base(const std::weak_ptr<instance_data>& data) : data_(data) {}
// @todo try and make this private over time too
@@ -132,8 +133,7 @@ class IFC_PARSE_API Base {
class IFC_PARSE_API Entity : public Base {
public:
Entity() {}
Entity(const std::weak_ptr<instance_data>& data) : Base(data) {}
using Base::Base;
attribute_value get(const std::string& attribute_name) const;
@@ -149,7 +149,8 @@ class IFC_PARSE_API Entity : public Base {
class IFC_PARSE_API Select : public Base {
public:
Select() {}
// Select are constructed from Base as cast functions, not from data directly
Select(std::nullopt_t) noexcept : Base() {}
Select(const std::weak_ptr<instance_data>& data) : Base(data) {}
Select(const Base& base) : Base(base.data_weak()) {}
Base concrete() const {
@@ -163,8 +164,7 @@ class IFC_PARSE_API Select : public Base {
// Entity and DeclaredType
class IFC_PARSE_API DeclaredType : public Base {
public:
DeclaredType() {}
DeclaredType(const std::weak_ptr<instance_data>& data) : Base(data) {}
using Base::Base;
};
} // namespace express