mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-12 02:23:34 +00:00
Fix compilation of serializers and convert
This commit is contained in:
@@ -42,8 +42,8 @@ public:
|
||||
: OpenCascadeBasedSerializer(out_filename, settings)
|
||||
{}
|
||||
virtual ~IgesSerializer() {}
|
||||
void writeShape(const IfcGeom::ConversionResultShape* shape) {
|
||||
writer.AddShape(*(IfcGeom::OpenCascadeShape*)shape);
|
||||
void writeShape(const ifcopenshell::geometry::ConversionResultShape* shape) {
|
||||
writer.AddShape(*(ifcopenshell::geometry::OpenCascadeShape*)shape);
|
||||
}
|
||||
void finalize() {
|
||||
writer.Write(out_filename.c_str());
|
||||
|
||||
@@ -36,19 +36,19 @@ bool OpenCascadeBasedSerializer::ready() {
|
||||
return succeeded;
|
||||
}
|
||||
|
||||
void OpenCascadeBasedSerializer::write(const IfcGeom::NativeElement<real_t>* o) {
|
||||
IfcGeom::OpenCascadeShape* occt_shape = ((IfcGeom::OpenCascadeShape*) o->geometry().as_compound());
|
||||
void OpenCascadeBasedSerializer::write(const ifcopenshell::geometry::NativeElement* o) {
|
||||
ifcopenshell::geometry::OpenCascadeShape* occt_shape = ((ifcopenshell::geometry::OpenCascadeShape*) o->geometry().as_compound());
|
||||
TopoDS_Shape compound = occt_shape->shape();
|
||||
delete occt_shape;
|
||||
|
||||
if (o->geometry().settings().get(IfcGeom::IteratorSettings::CONVERT_BACK_UNITS)) {
|
||||
if (o->geometry().settings().get(ifcopenshell::geometry::settings::CONVERT_BACK_UNITS)) {
|
||||
gp_Trsf scale;
|
||||
scale.SetScaleFactor(1.0 / o->geometry().settings().unit_magnitude());
|
||||
|
||||
compound = BRepBuilderAPI_Transform(compound, scale, true).Shape();
|
||||
}
|
||||
|
||||
IfcGeom::OpenCascadeShape s(compound);
|
||||
ifcopenshell::geometry::OpenCascadeShape s(compound);
|
||||
writeShape(&s);
|
||||
}
|
||||
|
||||
|
||||
@@ -37,9 +37,9 @@ public:
|
||||
virtual ~OpenCascadeBasedSerializer() {}
|
||||
void writeHeader() {}
|
||||
bool ready();
|
||||
virtual void writeShape(const IfcGeom::ConversionResultShape* shape) = 0;
|
||||
void write(const IfcGeom::TriangulationElement<real_t>* /*o*/) {}
|
||||
void write(const IfcGeom::NativeElement<real_t>* o);
|
||||
virtual void writeShape(const ifcopenshell::geometry::ConversionResultShape* shape) = 0;
|
||||
void write(const ifcopenshell::geometry::TriangulationElement* /*o*/) {}
|
||||
void write(const ifcopenshell::geometry::NativeElement* o);
|
||||
bool isTesselated() const { return false; }
|
||||
void setFile(IfcParse::IfcFile*) {}
|
||||
};
|
||||
|
||||
@@ -23,8 +23,6 @@
|
||||
#include <STEPControl_Writer.hxx>
|
||||
#include <Interface_Static.hxx>
|
||||
|
||||
#include "../ifcgeom/schema_agnostic/IfcGeomIterator.h"
|
||||
|
||||
#include "../serializers/OpenCascadeBasedSerializer.h"
|
||||
|
||||
class StepSerializer : public OpenCascadeBasedSerializer
|
||||
@@ -36,10 +34,10 @@ public:
|
||||
: OpenCascadeBasedSerializer(out_filename, settings)
|
||||
{}
|
||||
virtual ~StepSerializer() {}
|
||||
void writeShape(const IfcGeom::ConversionResultShape* shape) {
|
||||
void writeShape(const ifcopenshell::geometry::ConversionResultShape* shape) {
|
||||
std::stringstream ss;
|
||||
std::streambuf *sb = std::cout.rdbuf(ss.rdbuf());
|
||||
writer.Transfer(((IfcGeom::OpenCascadeShape*)shape)->shape(), STEPControl_AsIs);
|
||||
writer.Transfer(((ifcopenshell::geometry::OpenCascadeShape*)shape)->shape(), STEPControl_AsIs);
|
||||
std::cout.rdbuf(sb);
|
||||
}
|
||||
void finalize() {
|
||||
|
||||
@@ -285,7 +285,7 @@ SvgSerializer::path_object& SvgSerializer::start_path(IfcUtil::IfcBaseEntity* st
|
||||
return p;
|
||||
}
|
||||
|
||||
void SvgSerializer::write(const IfcGeom::NativeElement<real_t>* o)
|
||||
void SvgSerializer::write(const ifcopenshell::geometry::NativeElement* o)
|
||||
{
|
||||
IfcUtil::IfcBaseEntity* storey = storey_;
|
||||
boost::optional<double> storey_elevation = boost::none;
|
||||
@@ -293,7 +293,7 @@ void SvgSerializer::write(const IfcGeom::NativeElement<real_t>* o)
|
||||
for (const auto& p : o->parents()) {
|
||||
if (p->type() == "IfcBuildingStorey") {
|
||||
try {
|
||||
const IfcGeom::ElementSettings& settings = o->geometry().settings();
|
||||
const ifcopenshell::geometry::element_settings& settings = o->geometry().settings();
|
||||
double e = *p->product()->get("Elevation");
|
||||
storey_elevation = e * settings.unit_magnitude();
|
||||
} catch (...) {
|
||||
@@ -312,7 +312,8 @@ void SvgSerializer::write(const IfcGeom::NativeElement<real_t>* o)
|
||||
|
||||
path_object& p = start_path(storey, nameElement(o));
|
||||
|
||||
IfcGeom::OpenCascadeShape* occt_shape = ((IfcGeom::OpenCascadeShape*) o->geometry().as_compound());
|
||||
// @todo check whether correct kernel is used
|
||||
ifcopenshell::geometry::OpenCascadeShape* occt_shape = ((ifcopenshell::geometry::OpenCascadeShape*) o->geometry().as_compound());
|
||||
TopoDS_Shape compound = occt_shape->shape();
|
||||
delete occt_shape;
|
||||
|
||||
@@ -443,7 +444,7 @@ void SvgSerializer::writeHeader() {
|
||||
svg_file << "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n";
|
||||
}
|
||||
|
||||
std::string SvgSerializer::nameElement(const IfcGeom::Element<real_t>* elem)
|
||||
std::string SvgSerializer::nameElement(const ifcopenshell::geometry::Element* elem)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
const std::string type = "product";
|
||||
@@ -471,11 +472,10 @@ std::string SvgSerializer::nameElement(const IfcUtil::IfcBaseEntity* elem) {
|
||||
void SvgSerializer::setFile(IfcParse::IfcFile* f) {
|
||||
file = f;
|
||||
|
||||
mapping_ = ifcopenshell::geometry::impl::mapping_implementations().construct(f);
|
||||
|
||||
auto storeys = f->instances_by_type("IfcBuildingStorey");
|
||||
if (!storeys || storeys->size() == 0) {
|
||||
|
||||
IfcGeom::Kernel kernel("opencascade", f);
|
||||
|
||||
std::vector<const IfcParse::declaration*> to_derive_from;
|
||||
to_derive_from.push_back(f->schema()->declaration_by_name("IfcBuilding"));
|
||||
to_derive_from.push_back(f->schema()->declaration_by_name("IfcSite"));
|
||||
@@ -485,10 +485,10 @@ void SvgSerializer::setFile(IfcParse::IfcFile* f) {
|
||||
for (auto jt = insts->begin(); jt != insts->end(); ++jt) {
|
||||
IfcUtil::IfcBaseEntity* product = (IfcUtil::IfcBaseEntity*) *jt;
|
||||
if (!product->get("ObjectPlacement")->isNull()) {
|
||||
IfcGeom::ConversionResultPlacement* trsf;
|
||||
if (kernel.convert_placement(*product->get("ObjectPlacement"), trsf)) {
|
||||
double X, Y, Z;
|
||||
trsf->TranslationPart(X, Y, Z);
|
||||
auto item = mapping_->map(*product->get("ObjectPlacement"));
|
||||
if (item) {
|
||||
auto matrix = (ifcopenshell::geometry::taxonomy::matrix4*) item;
|
||||
const double& Z = matrix->components(3, 2);
|
||||
setSectionHeight(Z + 1.);
|
||||
Logger::Warning("No building storeys encountered, used for reference:", product);
|
||||
return;
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "../serializers/util.h"
|
||||
|
||||
#include "../ifcparse/utils.h"
|
||||
#include "../ifcgeom/abstract_mapping.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
@@ -45,6 +46,7 @@ protected:
|
||||
std::vector< boost::shared_ptr<util::string_buffer::float_item> > radii;
|
||||
IfcParse::IfcFile* file;
|
||||
IfcUtil::IfcBaseEntity* storey_;
|
||||
ifcopenshell::geometry::abstract_mapping* mapping_;
|
||||
public:
|
||||
SvgSerializer(const std::string& out_filename, const SerializerSettings& settings)
|
||||
: GeometrySerializer(settings)
|
||||
@@ -63,8 +65,8 @@ public:
|
||||
void growBoundingBox(double x, double y) { if (x < xmin) xmin = x; if (x > xmax) xmax = x; if (y < ymin) ymin = y; if (y > ymax) ymax = y; }
|
||||
void writeHeader();
|
||||
bool ready();
|
||||
void write(const IfcGeom::TriangulationElement<real_t>* /*o*/) {}
|
||||
void write(const IfcGeom::NativeElement<real_t>* o);
|
||||
void write(const ifcopenshell::geometry::TriangulationElement* /*o*/) {}
|
||||
void write(const ifcopenshell::geometry::NativeElement* o);
|
||||
void write(path_object& p, const TopoDS_Wire& wire);
|
||||
path_object& start_path(IfcUtil::IfcBaseEntity* storey, const std::string& id);
|
||||
bool isTesselated() const { return false; }
|
||||
@@ -73,7 +75,7 @@ public:
|
||||
void setFile(IfcParse::IfcFile* f);
|
||||
void setBoundingRectangle(double width, double height);
|
||||
void setSectionHeight(double h, IfcUtil::IfcBaseEntity* storey = 0) { section_height = h; storey_ = storey; }
|
||||
std::string nameElement(const IfcGeom::Element<real_t>* elem);
|
||||
std::string nameElement(const ifcopenshell::geometry::Element* elem);
|
||||
std::string nameElement(const IfcUtil::IfcBaseEntity* elem);
|
||||
};
|
||||
|
||||
|
||||
@@ -58,38 +58,39 @@ void WaveFrontOBJSerializer::writeHeader() {
|
||||
mtl_stream << "# File generated by IfcOpenShell " << IFCOPENSHELL_VERSION << "\n";
|
||||
}
|
||||
|
||||
void WaveFrontOBJSerializer::writeMaterial(const IfcGeom::Material& style)
|
||||
void WaveFrontOBJSerializer::writeMaterial(const ifcopenshell::geometry::taxonomy::style& style)
|
||||
{
|
||||
std::string material_name = (settings().get(SerializerSettings::USE_MATERIAL_NAMES)
|
||||
? style.original_name() : style.name());
|
||||
// @todo original_name
|
||||
std::string material_name = *(settings().get(SerializerSettings::USE_MATERIAL_NAMES)
|
||||
? style.name : style.name);
|
||||
IfcUtil::sanitate_material_name(material_name);
|
||||
mtl_stream << "newmtl " << material_name << "\n";
|
||||
|
||||
if (style.hasDiffuse()) {
|
||||
const double* diffuse = style.diffuse();
|
||||
if (style.diffuse) {
|
||||
auto diffuse = style.diffuse->components;
|
||||
mtl_stream << "Kd " << diffuse[0] << " " << diffuse[1] << " " << diffuse[2] << "\n";
|
||||
}
|
||||
if (style.hasSpecular()) {
|
||||
const double* specular = style.specular();
|
||||
if (style.specular) {
|
||||
auto specular = style.specular->components;
|
||||
mtl_stream << "Ks " << specular[0] << " " << specular[1] << " " << specular[2] << "\n";
|
||||
}
|
||||
if (style.hasSpecularity()) {
|
||||
mtl_stream << "Ns " << style.specularity() << "\n";
|
||||
if (style.specularity) {
|
||||
mtl_stream << "Ns " << *style.specularity << "\n";
|
||||
}
|
||||
if (style.hasTransparency()) {
|
||||
const double transparency = 1.0 - style.transparency();
|
||||
if (style.transparency) {
|
||||
const double transparency = 1.0 - *style.transparency;
|
||||
if (transparency < 1) {
|
||||
mtl_stream << "d " << transparency << "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WaveFrontOBJSerializer::write(const IfcGeom::TriangulationElement<real_t>* o)
|
||||
void WaveFrontOBJSerializer::write(const ifcopenshell::geometry::TriangulationElement* o)
|
||||
{
|
||||
obj_stream << "g " << object_id(o) << "\n";
|
||||
obj_stream << "s 1" << "\n";
|
||||
|
||||
const IfcGeom::Representation::Triangulation<real_t>& mesh = o->geometry();
|
||||
const ifcopenshell::geometry::Representation::Triangulation& mesh = o->geometry();
|
||||
|
||||
const int vcount = (int)mesh.verts().size() / 3;
|
||||
for ( std::vector<real_t>::const_iterator it = mesh.verts().begin(); it != mesh.verts().end(); ) {
|
||||
@@ -121,9 +122,10 @@ void WaveFrontOBJSerializer::write(const IfcGeom::TriangulationElement<real_t>*
|
||||
|
||||
const int material_id = *(material_it++);
|
||||
if (material_id != previous_material_id) {
|
||||
const IfcGeom::Material& material = mesh.materials()[material_id];
|
||||
std::string material_name = (settings().get(SerializerSettings::USE_MATERIAL_NAMES)
|
||||
? material.original_name() : material.name());
|
||||
const ifcopenshell::geometry::taxonomy::style& material = mesh.materials()[material_id];
|
||||
// @todo original_name
|
||||
std::string material_name = *(settings().get(SerializerSettings::USE_MATERIAL_NAMES)
|
||||
? material.name : material.name);
|
||||
IfcUtil::sanitate_material_name(material_name);
|
||||
obj_stream << "usemtl " << material_name << "\n";
|
||||
if (materials.find(material_name) == materials.end()) {
|
||||
@@ -165,9 +167,10 @@ void WaveFrontOBJSerializer::write(const IfcGeom::TriangulationElement<real_t>*
|
||||
const int material_id = *(material_it++);
|
||||
|
||||
if (material_id != previous_material_id) {
|
||||
const IfcGeom::Material& material = mesh.materials()[material_id];
|
||||
std::string material_name = (settings().get(SerializerSettings::USE_MATERIAL_NAMES)
|
||||
? material.original_name() : material.name());
|
||||
const ifcopenshell::geometry::taxonomy::style& material = mesh.materials()[material_id];
|
||||
// @todo original_name
|
||||
std::string material_name = *(settings().get(SerializerSettings::USE_MATERIAL_NAMES)
|
||||
? material.name : material.name);
|
||||
IfcUtil::sanitate_material_name(material_name);
|
||||
obj_stream << "usemtl " << material_name << "\n";
|
||||
if (materials.find(material_name) == materials.end()) {
|
||||
|
||||
@@ -39,9 +39,9 @@ public:
|
||||
virtual ~WaveFrontOBJSerializer() {}
|
||||
bool ready();
|
||||
void writeHeader();
|
||||
void writeMaterial(const IfcGeom::Material& style);
|
||||
void write(const IfcGeom::TriangulationElement<real_t>* o);
|
||||
void write(const IfcGeom::NativeElement<real_t>* /*o*/) {}
|
||||
void writeMaterial(const ifcopenshell::geometry::taxonomy::style& style);
|
||||
void write(const ifcopenshell::geometry::TriangulationElement* o);
|
||||
void write(const ifcopenshell::geometry::NativeElement* /*o*/) {}
|
||||
void finalize() {}
|
||||
bool isTesselated() const { return true; }
|
||||
void setUnitNameAndMagnitude(const std::string& /*name*/, float /*magnitude*/) {}
|
||||
|
||||
@@ -129,11 +129,13 @@ boost::optional<std::string> format_attribute(ifcopenshell::geometry::abstract_m
|
||||
auto matrix = (ifcopenshell::geometry::taxonomy::matrix4*) placement;
|
||||
|
||||
std::stringstream stream;
|
||||
for (int i = 0; i < 16; ++i) {
|
||||
const double trsf_value = matrix->components[i];
|
||||
stream << trsf_value;
|
||||
if (i != 15) {
|
||||
stream << " ";
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
for (int j = 0; j < 4; ++j) {
|
||||
const double trsf_value = matrix->components(j, i);
|
||||
stream << trsf_value;
|
||||
if (i < 3 && j < 3) {
|
||||
stream << " ";
|
||||
}
|
||||
}
|
||||
}
|
||||
value = stream.str();
|
||||
@@ -475,7 +477,7 @@ void POSTFIX_SCHEMA(XmlSerializer)::finalize() {
|
||||
for (IfcEntityList::it it = unit_assignments->begin(); it != unit_assignments->end(); ++it) {
|
||||
if ((*it)->declaration().is(IfcSchema::IfcNamedUnit::Class())) {
|
||||
IfcSchema::IfcNamedUnit* named_unit = (*it)->as<IfcSchema::IfcNamedUnit>();
|
||||
ptree& node = format_entity_instance(mapping, named_unit, units);
|
||||
ptree& node = format_entity_instance(mapping_, named_unit, units);
|
||||
node.put("<xmlattr>.SI_equivalent", IfcParse::get_SI_equivalent<IfcSchema>(named_unit));
|
||||
} else if ((*it)->declaration().is(IfcSchema::IfcMonetaryUnit::Class())) {
|
||||
format_entity_instance(mapping_, (*it)->as<IfcSchema::IfcMonetaryUnit>(), units);
|
||||
|
||||
Reference in New Issue
Block a user