mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-20 15:08:51 +00:00
Serialized.setFile: use file ref instead of pointer for safety
This commit is contained in:
@@ -906,7 +906,7 @@ int main(int argc, char** argv) {
|
|||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
serializer->setFile(ifc_file);
|
serializer->setFile(*ifc_file);
|
||||||
|
|
||||||
if (context_iterator && geometry_settings.get<ifcopenshell::geometry::settings::ConvertBackUnits>().get()) {
|
if (context_iterator && geometry_settings.get<ifcopenshell::geometry::settings::ConvertBackUnits>().get()) {
|
||||||
serializer->setUnitNameAndMagnitude(context_iterator->unit_name(), static_cast<float>(context_iterator->unit_magnitude()));
|
serializer->setUnitNameAndMagnitude(context_iterator->unit_name(), static_cast<float>(context_iterator->unit_magnitude()));
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ public:
|
|||||||
virtual bool is_streaming() const { return false; }
|
virtual bool is_streaming() const { return false; }
|
||||||
virtual void writeHeader() = 0;
|
virtual void writeHeader() = 0;
|
||||||
virtual void finalize() = 0;
|
virtual void finalize() = 0;
|
||||||
virtual void setFile(ifcopenshell::file*) = 0;
|
virtual void setFile(ifcopenshell::file&) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -350,7 +350,7 @@ public:
|
|||||||
serializer_->finalize();
|
serializer_->finalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setFile(ifcopenshell::file* file) override {
|
void setFile(ifcopenshell::file& file) override {
|
||||||
serializer_->setFile(file);
|
serializer_->setFile(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -405,7 +405,7 @@ private:
|
|||||||
$self->finalize();
|
$self->finalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setFile(ifcopenshell::file* file) {
|
void setFile(ifcopenshell::file& file) {
|
||||||
$self->setFile(file);
|
$self->setFile(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -238,7 +238,7 @@ public:
|
|||||||
unit_name = name;
|
unit_name = name;
|
||||||
unit_magnitude = magnitude;
|
unit_magnitude = magnitude;
|
||||||
}
|
}
|
||||||
void setFile(ifcopenshell::file*) {}
|
void setFile(ifcopenshell::file&) {}
|
||||||
|
|
||||||
std::string object_id(const IfcGeom::Element* o) /*override*/;
|
std::string object_id(const IfcGeom::Element* o) /*override*/;
|
||||||
|
|
||||||
|
|||||||
@@ -530,7 +530,7 @@ namespace {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GltfSerializer::setFile(ifcopenshell::file* f) {
|
void GltfSerializer::setFile(ifcopenshell::file& f) {
|
||||||
if (!settings_.get<ifcopenshell::geometry::settings::WriteGltfEcef>().get()) {
|
if (!settings_.get<ifcopenshell::geometry::settings::WriteGltfEcef>().get()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -541,7 +541,7 @@ void GltfSerializer::setFile(ifcopenshell::file* f) {
|
|||||||
|
|
||||||
std::vector<express::Base> coordops;
|
std::vector<express::Base> coordops;
|
||||||
try {
|
try {
|
||||||
coordops = f->instances_by_type("IfcCoordinateOperation");
|
coordops = f.instances_by_type("IfcCoordinateOperation");
|
||||||
} catch (ifcopenshell::exception&) {
|
} catch (ifcopenshell::exception&) {
|
||||||
// Ignored. Schema likely doesn't support IfcCoordinateOperation.
|
// Ignored. Schema likely doesn't support IfcCoordinateOperation.
|
||||||
}
|
}
|
||||||
@@ -578,7 +578,7 @@ void GltfSerializer::setFile(ifcopenshell::file* f) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!crs_epsg) {
|
if (!crs_epsg) {
|
||||||
auto sites = f->instances_by_type("IfcSite");
|
auto sites = f.instances_by_type("IfcSite");
|
||||||
|
|
||||||
if (sites.size() == 1) {
|
if (sites.size() == 1) {
|
||||||
auto lat_attr = sites.front().as<express::Entity>().get("RefLatitude");
|
auto lat_attr = sites.front().as<express::Entity>().get("RefLatitude");
|
||||||
@@ -613,7 +613,7 @@ void GltfSerializer::setFile(ifcopenshell::file* f) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto contexts = f->instances_by_type_excl_subtypes("IfcGeometricRepresentationContext");
|
auto contexts = f.instances_by_type_excl_subtypes("IfcGeometricRepresentationContext");
|
||||||
|
|
||||||
if (!contexts.empty()) {
|
if (!contexts.empty()) {
|
||||||
auto context = contexts.front().as<express::Entity>();
|
auto context = contexts.front().as<express::Entity>();
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ public:
|
|||||||
void finalize();
|
void finalize();
|
||||||
bool isTesselated() const { return true; }
|
bool isTesselated() const { return true; }
|
||||||
void setUnitNameAndMagnitude(const std::string& /*name*/, float /*magnitude*/) {}
|
void setUnitNameAndMagnitude(const std::string& /*name*/, float /*magnitude*/) {}
|
||||||
void setFile(ifcopenshell::file*);
|
void setFile(ifcopenshell::file&);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ class JsonSerializer : public Serializer {
|
|||||||
}
|
}
|
||||||
implementation_->finalize();
|
implementation_->finalize();
|
||||||
}
|
}
|
||||||
void setFile(ifcopenshell::file*) { throw ifcopenshell::exception("Should be supplied on construction"); }
|
void setFile(ifcopenshell::file&) { throw ifcopenshell::exception("Should be supplied on construction"); }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ public:
|
|||||||
void write(const IfcGeom::TriangulationElement* /*o*/) {}
|
void write(const IfcGeom::TriangulationElement* /*o*/) {}
|
||||||
void write(const IfcGeom::BRepElement* o);
|
void write(const IfcGeom::BRepElement* o);
|
||||||
bool isTesselated() const { return false; }
|
bool isTesselated() const { return false; }
|
||||||
void setFile(ifcopenshell::file*) {}
|
void setFile(ifcopenshell::file&) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ public:
|
|||||||
void writeHeader() override {}
|
void writeHeader() override {}
|
||||||
|
|
||||||
void finalize() override;
|
void finalize() override;
|
||||||
void setFile(ifcopenshell::file*) override { throw ifcopenshell::exception("Streaming serializer uses input filename supplied on construction"); }
|
void setFile(ifcopenshell::file&) override { throw ifcopenshell::exception("Streaming serializer uses input filename supplied on construction"); }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -2463,10 +2463,10 @@ std::string SvgSerializer::nameElement(express::Base elem_) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void SvgSerializer::setFile(ifcopenshell::file* f) {
|
void SvgSerializer::setFile(ifcopenshell::file& f) {
|
||||||
using namespace ifcopenshell::geometry::settings;
|
using namespace ifcopenshell::geometry::settings;
|
||||||
|
|
||||||
file = f;
|
file = &f;
|
||||||
auto apply_section_heights_from_storeys = [&]() {
|
auto apply_section_heights_from_storeys = [&]() {
|
||||||
if (settings().get<SvgSectionHeightFromStoreys>().get()) {
|
if (settings().get<SvgSectionHeightFromStoreys>().get()) {
|
||||||
if (settings().get<SvgSectionHeight>().has()) {
|
if (settings().get<SvgSectionHeight>().has()) {
|
||||||
@@ -2477,15 +2477,15 @@ void SvgSerializer::setFile(ifcopenshell::file* f) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
auto storeys = f->instances_by_type("IfcBuildingStorey");
|
auto storeys = f.instances_by_type("IfcBuildingStorey");
|
||||||
if (storeys.empty()) {
|
if (storeys.empty()) {
|
||||||
auto mapping = ifcopenshell::geometry::impl::mapping_implementations().construct(file, geometry_settings_, logger());
|
auto mapping = ifcopenshell::geometry::impl::mapping_implementations().construct(file, geometry_settings_, logger());
|
||||||
|
|
||||||
std::vector<const ifcopenshell::declaration*> to_derive_from;
|
std::vector<const ifcopenshell::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("IfcBuilding"));
|
||||||
to_derive_from.push_back(f->schema()->declaration_by_name("IfcSite"));
|
to_derive_from.push_back(f.schema()->declaration_by_name("IfcSite"));
|
||||||
for (auto it = to_derive_from.begin(); it != to_derive_from.end(); ++it) {
|
for (auto it = to_derive_from.begin(); it != to_derive_from.end(); ++it) {
|
||||||
auto insts = f->instances_by_type(*it);
|
auto insts = f.instances_by_type(*it);
|
||||||
for (auto& inst : insts) {
|
for (auto& inst : insts) {
|
||||||
auto product = inst.as<express::Entity>();
|
auto product = inst.as<express::Entity>();
|
||||||
if (!product.get("ObjectPlacement").isNull()) {
|
if (!product.get("ObjectPlacement").isNull()) {
|
||||||
|
|||||||
@@ -650,7 +650,7 @@ public:
|
|||||||
bool isTesselated() const { return false; }
|
bool isTesselated() const { return false; }
|
||||||
void finalize();
|
void finalize();
|
||||||
void setUnitNameAndMagnitude(const std::string& /*name*/, float /*magnitude*/) {}
|
void setUnitNameAndMagnitude(const std::string& /*name*/, float /*magnitude*/) {}
|
||||||
void setFile(ifcopenshell::file* f);
|
void setFile(ifcopenshell::file& f);
|
||||||
void setBoundingRectangle(double width, double height);
|
void setBoundingRectangle(double width, double height);
|
||||||
void setSectionHeight(double h, express::Base storey = express::Base());
|
void setSectionHeight(double h, express::Base storey = express::Base());
|
||||||
void setSectionHeightsFromStoreys(double offset=1.2);
|
void setSectionHeightsFromStoreys(double offset=1.2);
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ public:
|
|||||||
void finalize() {}
|
void finalize() {}
|
||||||
bool isTesselated() const;
|
bool isTesselated() const;
|
||||||
void setUnitNameAndMagnitude(const std::string& /*name*/, float /*magnitude*/) {}
|
void setUnitNameAndMagnitude(const std::string& /*name*/, float /*magnitude*/) {}
|
||||||
void setFile(ifcopenshell::file*) {}
|
void setFile(ifcopenshell::file&) {}
|
||||||
std::string ttl_object_id(const IfcGeom::Element* o, const char* const postfix = nullptr);
|
std::string ttl_object_id(const IfcGeom::Element* o, const char* const postfix = nullptr);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ public:
|
|||||||
void finalize();
|
void finalize();
|
||||||
bool isTesselated() const { return true; }
|
bool isTesselated() const { return true; }
|
||||||
void setUnitNameAndMagnitude(const std::string&, float) {}
|
void setUnitNameAndMagnitude(const std::string&, float) {}
|
||||||
void setFile(ifcopenshell::file*) {}
|
void setFile(ifcopenshell::file&) {}
|
||||||
std::string object_id_unique(const IfcGeom::Element* o);
|
std::string object_id_unique(const IfcGeom::Element* o);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ public:
|
|||||||
void finalize() {}
|
void finalize() {}
|
||||||
bool isTesselated() const { return true; }
|
bool isTesselated() const { return true; }
|
||||||
void setUnitNameAndMagnitude(const std::string& /*name*/, float /*magnitude*/) {}
|
void setUnitNameAndMagnitude(const std::string& /*name*/, float /*magnitude*/) {}
|
||||||
void setFile(ifcopenshell::file*) {}
|
void setFile(ifcopenshell::file&) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ public:
|
|||||||
}
|
}
|
||||||
implementation_->finalize();
|
implementation_->finalize();
|
||||||
}
|
}
|
||||||
void setFile(ifcopenshell::file*) { throw ifcopenshell::exception("Should be supplied on construction"); }
|
void setFile(ifcopenshell::file&) { throw ifcopenshell::exception("Should be supplied on construction"); }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ class POSTFIX_SCHEMA(JsonSerializer) : public JsonSerializer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void finalize();
|
void finalize();
|
||||||
void setFile(ifcopenshell::file*) {}
|
void setFile(ifcopenshell::file&) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void finalize();
|
void finalize();
|
||||||
void setFile(ifcopenshell::file*) {}
|
void setFile(ifcopenshell::file&) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user