mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-26 10:11:46 +00:00
Fix SVG storey sorting and element naming
This commit is contained in:
@@ -465,7 +465,7 @@ void SvgSerializer::write(const IfcGeom::BRepElement<real_t>* o)
|
|||||||
// No intersection with bounding box, fail early
|
// No intersection with bounding box, fail early
|
||||||
if (zmin > cut_z || zmax < cut_z) continue;
|
if (zmin > cut_z || zmax < cut_z) continue;
|
||||||
|
|
||||||
po = &start_path(storey, nameElement(o));
|
po = &start_path(storey, nameElement(storey, o));
|
||||||
|
|
||||||
// Create a horizontal cross section 1 meter above the bottom point of the shape
|
// Create a horizontal cross section 1 meter above the bottom point of the shape
|
||||||
const gp_Pln pln(gp_Pnt(0, 0, cut_z), gp::DZ());
|
const gp_Pln pln(gp_Pnt(0, 0, cut_z), gp::DZ());
|
||||||
@@ -686,28 +686,41 @@ namespace {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string SvgSerializer::nameElement(const IfcGeom::Element<real_t>* elem) {
|
std::string SvgSerializer::nameElement(const IfcUtil::IfcBaseEntity* storey, const IfcGeom::Element<real_t>* elem) {
|
||||||
return nameElement_({ {"id", object_id(elem)}, {"class", elem->type()}, {"data-name", elem->name()} });
|
return nameElement_({
|
||||||
|
{"id", with_section_heights_from_storey_ ? object_id(storey, elem) : GeometrySerializer::object_id(elem)},
|
||||||
|
{"class", elem->type()},
|
||||||
|
{"data-name", elem->name()},
|
||||||
|
{"data-guid", elem->guid()}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string SvgSerializer::idElement(const IfcUtil::IfcBaseEntity* elem) {
|
||||||
|
const std::string type = elem->declaration().is("IfcBuildingStorey") ? "storey" : "product";
|
||||||
|
const std::string name =
|
||||||
|
(settings().get(SerializerSettings::USE_ELEMENT_GUIDS)
|
||||||
|
? static_cast<std::string>(*elem->get("GlobalId"))
|
||||||
|
: ((settings().get(SerializerSettings::USE_ELEMENT_NAMES) && !elem->get("Name")->isNull()))
|
||||||
|
? static_cast<std::string>(*elem->get("Name"))
|
||||||
|
: IfcParse::IfcGlobalId(*elem->get("GlobalId")).formatted());
|
||||||
|
return type + "-" + name;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string SvgSerializer::nameElement(const IfcUtil::IfcBaseEntity* elem) {
|
std::string SvgSerializer::nameElement(const IfcUtil::IfcBaseEntity* elem) {
|
||||||
if (elem == 0) { return ""; }
|
if (elem == 0) { return ""; }
|
||||||
|
|
||||||
const std::string& entity = elem->declaration().name();
|
const std::string& entity = elem->declaration().name();
|
||||||
const std::string type = elem->declaration().is("IfcBuildingStorey") ? "storey" : "product";
|
|
||||||
std::string ifc_name;
|
std::string ifc_name;
|
||||||
if (!elem->get("Name")->isNull()) {
|
if (!elem->get("Name")->isNull()) {
|
||||||
ifc_name = (std::string) *elem->get("Name");
|
ifc_name = (std::string) *elem->get("Name");
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string name =
|
return nameElement_({
|
||||||
(settings().get(SerializerSettings::USE_ELEMENT_GUIDS)
|
{"id", idElement(elem)},
|
||||||
? static_cast<std::string>(*elem->get("GlobalId"))
|
{"class", entity},
|
||||||
: ((settings().get(SerializerSettings::USE_ELEMENT_NAMES) && !elem->get("Name")->isNull()))
|
{"data-name", ifc_name},
|
||||||
? static_cast<std::string>(*elem->get("Name"))
|
{"data-guid", *elem->get("GlobalId")}
|
||||||
: IfcParse::IfcGlobalId(*elem->get("GlobalId")).formatted());
|
});
|
||||||
|
|
||||||
return nameElement_({ {"id", type + "-" + name}, {"class", entity}, {"data-name", ifc_name} });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SvgSerializer::setFile(IfcParse::IfcFile* f) {
|
void SvgSerializer::setFile(IfcParse::IfcFile* f) {
|
||||||
@@ -748,6 +761,7 @@ void SvgSerializer::setSectionHeight(double h, IfcUtil::IfcBaseEntity* storey) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SvgSerializer::setSectionHeightsFromStoreys(double offset) {
|
void SvgSerializer::setSectionHeightsFromStoreys(double offset) {
|
||||||
|
with_section_heights_from_storey_ = true;
|
||||||
section_heights.emplace();
|
section_heights.emplace();
|
||||||
auto storeys = file->instances_by_type("IfcBuildingStorey");
|
auto storeys = file->instances_by_type("IfcBuildingStorey");
|
||||||
const double lu = file->getUnit("LENGTHUNIT").second;
|
const double lu = file->getUnit("LENGTHUNIT").second;
|
||||||
|
|||||||
@@ -42,7 +42,11 @@ struct storey_sorter {
|
|||||||
b_elev = static_cast<double>(*b->get("Elevation"));
|
b_elev = static_cast<double>(*b->get("Elevation"));
|
||||||
} catch (...) {};
|
} catch (...) {};
|
||||||
if (a_elev && b_elev) {
|
if (a_elev && b_elev) {
|
||||||
return std::less<double>()(*a_elev, *b_elev);
|
if (std::equal_to<double>()(*a_elev, *b_elev)) {
|
||||||
|
return std::less<unsigned int>()(a->data().id(), b->data().id());
|
||||||
|
} else {
|
||||||
|
return std::less<double>()(*a_elev, *b_elev);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::optional<std::string> a_name, b_name;
|
boost::optional<std::string> a_name, b_name;
|
||||||
@@ -51,7 +55,11 @@ struct storey_sorter {
|
|||||||
b_name = static_cast<std::string>(*b->get("Name"));
|
b_name = static_cast<std::string>(*b->get("Name"));
|
||||||
} catch (...) {};
|
} catch (...) {};
|
||||||
if (a_name && b_name) {
|
if (a_name && b_name) {
|
||||||
return std::less<std::string>()(*a_name, *b_name);
|
if (std::equal_to<std::string>()(*a_name, *b_name)) {
|
||||||
|
return std::less<unsigned int>()(a->data().id(), b->data().id());
|
||||||
|
} else {
|
||||||
|
return std::less<std::string>()(*a_name, *b_name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return std::less<IfcUtil::IfcBaseEntity*>()(a, b);
|
return std::less<IfcUtil::IfcBaseEntity*>()(a, b);
|
||||||
@@ -65,7 +73,7 @@ protected:
|
|||||||
std::ofstream svg_file;
|
std::ofstream svg_file;
|
||||||
double xmin, ymin, xmax, ymax, width, height;
|
double xmin, ymin, xmax, ymax, width, height;
|
||||||
boost::optional<std::vector<std::pair<double, IfcUtil::IfcBaseEntity*>>> section_heights;
|
boost::optional<std::vector<std::pair<double, IfcUtil::IfcBaseEntity*>>> section_heights;
|
||||||
bool rescale, print_space_names_, print_space_areas_, draw_door_arcs_;
|
bool rescale, print_space_names_, print_space_areas_, draw_door_arcs_, with_section_heights_from_storey_;
|
||||||
std::multimap<IfcUtil::IfcBaseEntity*, path_object, storey_sorter> 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;
|
||||||
@@ -80,6 +88,7 @@ public:
|
|||||||
, ymin(+std::numeric_limits<double>::infinity())
|
, ymin(+std::numeric_limits<double>::infinity())
|
||||||
, xmax(-std::numeric_limits<double>::infinity())
|
, xmax(-std::numeric_limits<double>::infinity())
|
||||||
, ymax(-std::numeric_limits<double>::infinity())
|
, ymax(-std::numeric_limits<double>::infinity())
|
||||||
|
, with_section_heights_from_storey_(false)
|
||||||
, rescale(false)
|
, rescale(false)
|
||||||
, file(0)
|
, file(0)
|
||||||
, storey_(0)
|
, storey_(0)
|
||||||
@@ -104,8 +113,12 @@ public:
|
|||||||
void setPrintSpaceNames(bool b) { print_space_names_ = b; }
|
void setPrintSpaceNames(bool b) { print_space_names_ = b; }
|
||||||
void setPrintSpaceAreas(bool b) { print_space_areas_ = b; }
|
void setPrintSpaceAreas(bool b) { print_space_areas_ = b; }
|
||||||
void setDrawDoorArcs(bool b) { draw_door_arcs_ = b; }
|
void setDrawDoorArcs(bool b) { draw_door_arcs_ = b; }
|
||||||
std::string nameElement(const IfcGeom::Element<real_t>* elem);
|
std::string nameElement(const IfcUtil::IfcBaseEntity* storey, const IfcGeom::Element<real_t>* elem);
|
||||||
std::string nameElement(const IfcUtil::IfcBaseEntity* elem);
|
std::string nameElement(const IfcUtil::IfcBaseEntity* elem);
|
||||||
|
std::string idElement(const IfcUtil::IfcBaseEntity* elem);
|
||||||
|
std::string object_id(const IfcUtil::IfcBaseEntity* storey, const IfcGeom::Element<real_t>* o) {
|
||||||
|
return idElement(storey) + "-" + GeometrySerializer::object_id(o);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user