2013-03-24 10:48:39 +00:00
|
|
|
/********************************************************************************
|
|
|
|
|
* *
|
|
|
|
|
* This file is part of IfcOpenShell. *
|
|
|
|
|
* *
|
|
|
|
|
* IfcOpenShell is free software: you can redistribute it and/or modify *
|
|
|
|
|
* it under the terms of the Lesser GNU General Public License as published by *
|
|
|
|
|
* the Free Software Foundation, either version 3.0 of the License, or *
|
|
|
|
|
* (at your option) any later version. *
|
|
|
|
|
* *
|
|
|
|
|
* IfcOpenShell is distributed in the hope that it will be useful, *
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
|
* Lesser GNU General Public License for more details. *
|
|
|
|
|
* *
|
|
|
|
|
* You should have received a copy of the Lesser GNU General Public License *
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
|
|
|
|
* *
|
|
|
|
|
********************************************************************************/
|
|
|
|
|
|
|
|
|
|
#ifndef GEOMETRYSERIALIZER_H
|
|
|
|
|
#define GEOMETRYSERIALIZER_H
|
|
|
|
|
|
2021-10-18 11:38:01 +02:00
|
|
|
#include "../ifcgeom_schema_agnostic/Serializer.h"
|
2022-06-15 13:41:13 +02:00
|
|
|
#include "../ifcgeom_schema_agnostic/IfcGeomElement.h"
|
2013-03-24 10:48:39 +00:00
|
|
|
|
2017-01-11 12:00:51 +02:00
|
|
|
class SerializerSettings : public IfcGeom::IteratorSettings
|
|
|
|
|
{
|
|
|
|
|
public:
|
2021-07-11 15:01:31 +02:00
|
|
|
enum Setting : uint64_t
|
2017-01-11 12:00:51 +02:00
|
|
|
{
|
|
|
|
|
/// Use entity names instead of unique IDs for naming elements.
|
|
|
|
|
/// Applicable for OBJ, DAE, and SVG output.
|
2021-12-19 22:31:40 +01:00
|
|
|
USE_ELEMENT_NAMES = 1U << (IfcGeom::IteratorSettings::NUM_SETTINGS + 1U),
|
2017-01-11 12:00:51 +02:00
|
|
|
/// Use entity GUIDs instead of unique IDs for naming elements.
|
|
|
|
|
/// Applicable for OBJ, DAE, and SVG output.
|
2021-12-19 22:31:40 +01:00
|
|
|
USE_ELEMENT_GUIDS = 1U << (IfcGeom::IteratorSettings::NUM_SETTINGS + 2U),
|
2017-01-11 12:00:51 +02:00
|
|
|
/// Use material names instead of unique IDs for naming materials.
|
|
|
|
|
/// Applicable for OBJ and DAE output.
|
2021-12-19 22:31:40 +01:00
|
|
|
USE_MATERIAL_NAMES = 1U << (IfcGeom::IteratorSettings::NUM_SETTINGS + 3U),
|
2017-04-19 16:38:35 +02:00
|
|
|
/// Use element types instead of unique IDs for naming elements.
|
2017-04-19 12:07:03 +02:00
|
|
|
/// Applicable for DAE output.
|
2021-12-19 22:31:40 +01:00
|
|
|
USE_ELEMENT_TYPES = 1U << (IfcGeom::IteratorSettings::NUM_SETTINGS + 4U),
|
2017-04-19 12:07:03 +02:00
|
|
|
/// Order the elements using their IfcBuildingStorey parent
|
|
|
|
|
/// Applicable for DAE output
|
2021-12-19 22:31:40 +01:00
|
|
|
USE_ELEMENT_HIERARCHY = 1U << (IfcGeom::IteratorSettings::NUM_SETTINGS + 5U),
|
2020-08-16 14:35:39 +02:00
|
|
|
/// Use step ids for naming elements.
|
|
|
|
|
/// Applicable for OBJ, DAE, and SVG output.
|
2021-12-19 22:31:40 +01:00
|
|
|
USE_ELEMENT_STEPIDS = 1U << (IfcGeom::IteratorSettings::NUM_SETTINGS + 6U),
|
2021-01-09 15:08:30 +01:00
|
|
|
/// Use Y UP .
|
2020-12-10 18:44:23 +08:00
|
|
|
/// Applicable for OBJ output.
|
2022-01-09 15:14:13 +01:00
|
|
|
USE_Y_UP = 1ULL << (IfcGeom::IteratorSettings::NUM_SETTINGS + 7ULL),
|
2020-08-16 14:35:39 +02:00
|
|
|
/// Number of different setting flags.
|
2020-12-10 18:44:23 +08:00
|
|
|
NUM_SETTINGS = 7
|
2017-01-11 12:00:51 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
SerializerSettings()
|
2020-01-31 15:55:04 +01:00
|
|
|
: precision(DEFAULT_PRECISION) { }
|
2017-01-11 16:36:33 +02:00
|
|
|
|
|
|
|
|
/// Sets the precision used to format floating-point values, 15 by default.
|
|
|
|
|
/// Use a negative value to use the system's default precision (should be 6 typically).
|
|
|
|
|
short precision;
|
|
|
|
|
|
2017-01-11 19:20:03 +02:00
|
|
|
enum { DEFAULT_PRECISION = 15 };
|
2017-01-11 12:00:51 +02:00
|
|
|
};
|
|
|
|
|
|
2021-07-11 15:01:31 +02:00
|
|
|
class stream_or_filename {
|
|
|
|
|
private:
|
|
|
|
|
std::shared_ptr<std::ofstream> ofs_;
|
|
|
|
|
std::shared_ptr<std::ostringstream> oss_;
|
|
|
|
|
boost::optional<std::string> filename_;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
std::ostream& stream;
|
|
|
|
|
|
|
|
|
|
stream_or_filename(const std::string& fn)
|
|
|
|
|
: ofs_(new std::ofstream(IfcUtil::path::from_utf8(fn).c_str()))
|
|
|
|
|
, stream(*ofs_)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
stream_or_filename()
|
|
|
|
|
: oss_(new std::ostringstream)
|
|
|
|
|
, stream(*oss_)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
std::string get_value() const {
|
|
|
|
|
return oss_->str();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boost::optional<std::string> filename() const {
|
|
|
|
|
return filename_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool is_ready() {
|
|
|
|
|
if (ofs_) {
|
|
|
|
|
return ofs_->is_open();
|
|
|
|
|
} else {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2015-02-06 13:07:50 +00:00
|
|
|
class GeometrySerializer : public Serializer {
|
2013-03-24 10:48:39 +00:00
|
|
|
public:
|
2021-10-18 11:38:01 +02:00
|
|
|
enum read_type { READ_BREP, READ_TRIANGULATION };
|
|
|
|
|
|
2017-01-11 12:00:51 +02:00
|
|
|
GeometrySerializer(const SerializerSettings& settings) : settings_(settings) {}
|
2013-03-24 10:48:39 +00:00
|
|
|
virtual ~GeometrySerializer() {}
|
2015-02-06 13:07:50 +00:00
|
|
|
|
|
|
|
|
virtual bool isTesselated() const = 0;
|
2021-07-11 15:00:59 +02:00
|
|
|
virtual void write(const IfcGeom::TriangulationElement* o) = 0;
|
|
|
|
|
virtual void write(const IfcGeom::BRepElement* o) = 0;
|
2013-12-31 14:10:38 +00:00
|
|
|
virtual void setUnitNameAndMagnitude(const std::string& name, float magnitude) = 0;
|
2021-11-02 11:39:49 +01:00
|
|
|
virtual IfcGeom::Element* read(IfcParse::IfcFile& f, const std::string& guid, const std::string& representation_id, read_type rt = READ_BREP) = 0;
|
2016-03-10 11:35:32 +02:00
|
|
|
|
2017-01-11 12:00:51 +02:00
|
|
|
const SerializerSettings& settings() const { return settings_; }
|
|
|
|
|
SerializerSettings& settings() { return settings_; }
|
2016-03-10 11:35:32 +02:00
|
|
|
|
2018-06-07 14:34:25 +03:00
|
|
|
/// Returns ID for the object depending on the used setting.
|
2021-07-11 15:00:59 +02:00
|
|
|
virtual std::string object_id(const IfcGeom::Element* o)
|
2018-06-07 14:34:25 +03:00
|
|
|
{
|
|
|
|
|
if (settings_.get(SerializerSettings::USE_ELEMENT_GUIDS)) return o->guid();
|
|
|
|
|
if (settings_.get(SerializerSettings::USE_ELEMENT_NAMES)) return o->name();
|
2020-08-16 14:35:39 +02:00
|
|
|
if (settings_.get(SerializerSettings::USE_ELEMENT_STEPIDS)) return "id-" + boost::lexical_cast<std::string>(o->id());
|
|
|
|
|
return o->unique_id();
|
2018-06-07 14:34:25 +03:00
|
|
|
}
|
|
|
|
|
|
2016-03-10 11:35:32 +02:00
|
|
|
protected:
|
2017-01-11 12:00:51 +02:00
|
|
|
SerializerSettings settings_;
|
2013-03-24 10:48:39 +00:00
|
|
|
};
|
|
|
|
|
|
2021-10-18 11:38:01 +02:00
|
|
|
class WriteOnlyGeometrySerializer : public GeometrySerializer {
|
|
|
|
|
public:
|
|
|
|
|
WriteOnlyGeometrySerializer(const SerializerSettings& settings) : GeometrySerializer(settings) {}
|
|
|
|
|
|
2021-11-02 11:39:49 +01:00
|
|
|
virtual IfcGeom::Element* read(IfcParse::IfcFile&, const std::string&, const std::string&, read_type = READ_BREP) {
|
2021-10-18 11:38:01 +02:00
|
|
|
throw std::runtime_error("Not supported");
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2016-03-10 11:35:32 +02:00
|
|
|
#endif
|