mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-21 22:50:56 +00:00
SVG: Sort storeys and output elements names
This commit is contained in:
@@ -581,7 +581,7 @@ namespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string SvgSerializer::nameElement(const IfcGeom::Element<real_t>* elem) {
|
std::string SvgSerializer::nameElement(const IfcGeom::Element<real_t>* elem) {
|
||||||
return nameElement_({ {"id", object_id(elem)}, {"class", elem->type()} });
|
return nameElement_({ {"id", object_id(elem)}, {"class", elem->type()}, {"data-name", elem->name()} });
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string SvgSerializer::nameElement(const IfcUtil::IfcBaseEntity* elem) {
|
std::string SvgSerializer::nameElement(const IfcUtil::IfcBaseEntity* elem) {
|
||||||
@@ -589,6 +589,10 @@ std::string SvgSerializer::nameElement(const IfcUtil::IfcBaseEntity* elem) {
|
|||||||
|
|
||||||
const std::string& entity = elem->declaration().name();
|
const std::string& entity = elem->declaration().name();
|
||||||
const std::string type = elem->declaration().is("IfcBuildingStorey") ? "storey" : "product";
|
const std::string type = elem->declaration().is("IfcBuildingStorey") ? "storey" : "product";
|
||||||
|
std::string ifc_name;
|
||||||
|
if (!elem->get("Name")->isNull()) {
|
||||||
|
ifc_name = *elem->get("Name");
|
||||||
|
}
|
||||||
|
|
||||||
const std::string name =
|
const std::string name =
|
||||||
(settings().get(SerializerSettings::USE_ELEMENT_GUIDS)
|
(settings().get(SerializerSettings::USE_ELEMENT_GUIDS)
|
||||||
@@ -597,7 +601,7 @@ std::string SvgSerializer::nameElement(const IfcUtil::IfcBaseEntity* elem) {
|
|||||||
? static_cast<std::string>(*elem->get("Name"))
|
? static_cast<std::string>(*elem->get("Name"))
|
||||||
: IfcParse::IfcGlobalId(*elem->get("GlobalId")).formatted());
|
: IfcParse::IfcGlobalId(*elem->get("GlobalId")).formatted());
|
||||||
|
|
||||||
return nameElement_({ {"id", type + "-" + name}, {"class", entity} });
|
return nameElement_({ {"id", type + "-" + name}, {"class", entity}, {"data-name", ifc_name} });
|
||||||
}
|
}
|
||||||
|
|
||||||
void SvgSerializer::setFile(IfcParse::IfcFile* f) {
|
void SvgSerializer::setFile(IfcParse::IfcFile* f) {
|
||||||
|
|||||||
@@ -31,6 +31,33 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
|
struct storey_sorter {
|
||||||
|
bool operator()(IfcUtil::IfcBaseEntity* a, IfcUtil::IfcBaseEntity* b) const {
|
||||||
|
const bool a_is_storey = a->declaration().is("IfcBuildingStorey");
|
||||||
|
const bool b_is_storey = b->declaration().is("IfcBuildingStorey");
|
||||||
|
if (a_is_storey && b_is_storey) {
|
||||||
|
boost::optional<double> a_elev, b_elev;
|
||||||
|
try {
|
||||||
|
a_elev = static_cast<double>(*a->get("Elevation"));
|
||||||
|
b_elev = static_cast<double>(*b->get("Elevation"));
|
||||||
|
} catch (...) {};
|
||||||
|
if (a_elev && b_elev) {
|
||||||
|
return std::less<double>()(*a_elev, *b_elev);
|
||||||
|
}
|
||||||
|
|
||||||
|
boost::optional<std::string> a_name, b_name;
|
||||||
|
try {
|
||||||
|
a_name = static_cast<std::string>(*a->get("Name"));
|
||||||
|
b_name = static_cast<std::string>(*b->get("Name"));
|
||||||
|
} catch (...) {};
|
||||||
|
if (a_name && b_name) {
|
||||||
|
return std::less<std::string>()(*a_name, *b_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return std::less<IfcUtil::IfcBaseEntity*>()(a, b);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class SvgSerializer : public GeometrySerializer {
|
class SvgSerializer : public GeometrySerializer {
|
||||||
public:
|
public:
|
||||||
typedef std::pair<std::string, std::vector<util::string_buffer> > path_object;
|
typedef std::pair<std::string, std::vector<util::string_buffer> > path_object;
|
||||||
@@ -39,7 +66,7 @@ protected:
|
|||||||
double xmin, ymin, xmax, ymax, width, height;
|
double xmin, ymin, xmax, ymax, width, height;
|
||||||
boost::optional<double> section_height;
|
boost::optional<double> section_height;
|
||||||
bool rescale, print_space_names_, print_space_areas_;
|
bool rescale, print_space_names_, print_space_areas_;
|
||||||
std::multimap<IfcUtil::IfcBaseEntity*, path_object> paths;
|
std::multimap<IfcUtil::IfcBaseEntity*, path_object, storey_sorter> paths;
|
||||||
std::vector< boost::shared_ptr<util::string_buffer::float_item> > xcoords;
|
std::vector< boost::shared_ptr<util::string_buffer::float_item> > xcoords;
|
||||||
std::vector< boost::shared_ptr<util::string_buffer::float_item> > ycoords;
|
std::vector< boost::shared_ptr<util::string_buffer::float_item> > ycoords;
|
||||||
std::vector< boost::shared_ptr<util::string_buffer::float_item> > radii;
|
std::vector< boost::shared_ptr<util::string_buffer::float_item> > radii;
|
||||||
|
|||||||
Reference in New Issue
Block a user