IfcConvert --svg-xmlns option

This commit is contained in:
Thomas Krijnen
2020-12-30 14:44:43 +01:00
parent de5ce28a78
commit a5adb01dff
3 changed files with 21 additions and 5 deletions
+3
View File
@@ -374,6 +374,8 @@ int main(int argc, char** argv) {
"Creates SVG cross section drawings automatically based on model extents") "Creates SVG cross section drawings automatically based on model extents")
("auto-elevation", ("auto-elevation",
"Creates SVG elevation drawings automatically based on model extents") "Creates SVG elevation drawings automatically based on model extents")
("svg-xmlns",
"Stores name and guid in a separate namespace as opposed to data-name, data-guid")
("door-arcs", "Draw door openings arcs for IfcDoor elements") ("door-arcs", "Draw door openings arcs for IfcDoor elements")
("section-height", po::value<double>(&section_height), ("section-height", po::value<double>(&section_height),
"Specifies the cut section height for SVG 2D geometry.") "Specifies the cut section height for SVG 2D geometry.")
@@ -956,6 +958,7 @@ int main(int argc, char** argv) {
if (vmap.count("auto-elevation")) { if (vmap.count("auto-elevation")) {
static_cast<SvgSerializer*>(serializer.get())->setAutoElevation(true); static_cast<SvgSerializer*>(serializer.get())->setAutoElevation(true);
} }
static_cast<SvgSerializer*>(serializer.get())->setUseNamespace(vmap.count("svg-xmlns") > 0);
if (relative_center_x && relative_center_y) { if (relative_center_x && relative_center_y) {
static_cast<SvgSerializer*>(serializer.get())->setDrawingCenter(*relative_center_x, *relative_center_y); static_cast<SvgSerializer*>(serializer.get())->setDrawingCenter(*relative_center_x, *relative_center_y);
} }
+8 -5
View File
@@ -1093,7 +1093,7 @@ void SvgSerializer::finalize() {
} else { } else {
auto n = it->first.second; auto n = it->first.second;
IfcUtil::escape_xml(n); IfcUtil::escape_xml(n);
svg_file << " <g data-name=\"" << n << "\" class=\"section\">\n"; svg_file << " <g " << namespace_prefix_ << "name=\"" << n << "\" class=\"section\">\n";
} }
} }
svg_file << " <g " << it->second.first << ">\n"; svg_file << " <g " << it->second.first << ">\n";
@@ -1113,6 +1113,9 @@ void SvgSerializer::finalize() {
void SvgSerializer::writeHeader() { void SvgSerializer::writeHeader() {
svg_file << "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\""; svg_file << "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"";
if (use_namespace_) {
svg_file << " xmlns:ifc=\"http://www.ifcopenshell.org/ns\"";
}
if (scale_) { if (scale_) {
svg_file << svg_file <<
" width=\"" << width << "mm\"" " width=\"" << width << "mm\""
@@ -1183,8 +1186,8 @@ std::string SvgSerializer::nameElement(const IfcUtil::IfcBaseEntity* storey, con
return nameElement_({ return nameElement_({
{"id", with_section_heights_from_storey_ ? object_id(storey, elem) : GeometrySerializer::object_id(elem)}, {"id", with_section_heights_from_storey_ ? object_id(storey, elem) : GeometrySerializer::object_id(elem)},
{"class", elem->type()}, {"class", elem->type()},
{"data-name", n}, {namespace_prefix_ + "name", n},
{"data-guid", elem->guid()} {namespace_prefix_ + "guid", elem->guid()}
}); });
} }
@@ -1214,8 +1217,8 @@ std::string SvgSerializer::nameElement(const IfcUtil::IfcBaseEntity* elem) {
return nameElement_({ return nameElement_({
{"id", idElement(elem)}, {"id", idElement(elem)},
{"class", entity}, {"class", entity},
{"data-name", ifc_name}, {namespace_prefix_ + "name", ifc_name},
{"data-guid", *elem->get("GlobalId")} {namespace_prefix_ + "guid", *elem->get("GlobalId")}
}); });
} }
+10
View File
@@ -121,6 +121,7 @@ protected:
bool with_section_heights_from_storey_, rescale, print_space_names_, print_space_areas_; bool with_section_heights_from_storey_, rescale, print_space_names_, print_space_areas_;
bool draw_door_arcs_, is_floor_plan_; bool draw_door_arcs_, is_floor_plan_;
bool auto_section_, auto_elevation_; bool auto_section_, auto_elevation_;
bool use_namespace_;
IfcParse::IfcFile* file; IfcParse::IfcFile* file;
IfcUtil::IfcBaseEntity* storey_; IfcUtil::IfcBaseEntity* storey_;
@@ -134,6 +135,8 @@ protected:
std::list<geometry_data> element_buffer_; std::list<geometry_data> element_buffer_;
Handle(HLRBRep_Algo) hlr; Handle(HLRBRep_Algo) hlr;
std::string namespace_prefix_;
public: public:
SvgSerializer(const std::string& out_filename, const SerializerSettings& settings) SvgSerializer(const std::string& out_filename, const SerializerSettings& settings)
: GeometrySerializer(settings) : GeometrySerializer(settings)
@@ -150,11 +153,13 @@ public:
, is_floor_plan_(true) , is_floor_plan_(true)
, auto_section_(false) , auto_section_(false)
, auto_elevation_(false) , auto_elevation_(false)
, use_namespace_(false)
, file(0) , file(0)
, storey_(0) , storey_(0)
, xcoords_begin(0) , xcoords_begin(0)
, ycoords_begin(0) , ycoords_begin(0)
, radii_begin(0) , radii_begin(0)
, namespace_prefix_("data-")
{} {}
void addXCoordinate(const boost::shared_ptr<util::string_buffer::float_item>& fi) { xcoords.push_back(fi); } void addXCoordinate(const boost::shared_ptr<util::string_buffer::float_item>& fi) { xcoords.push_back(fi); }
void addYCoordinate(const boost::shared_ptr<util::string_buffer::float_item>& fi) { ycoords.push_back(fi); } void addYCoordinate(const boost::shared_ptr<util::string_buffer::float_item>& fi) { ycoords.push_back(fi); }
@@ -197,6 +202,11 @@ public:
auto_elevation_ = b; auto_elevation_ = b;
} }
void setUseNamespace(bool b) {
use_namespace_ = b;
namespace_prefix_ = use_namespace_ ? "ifc:" : "data-";
}
void setScale(double s) { scale_ = s; } void setScale(double s) { scale_ = s; }
void setDrawingCenter(double x, double y) { void setDrawingCenter(double x, double y) {
center_x_ = x; center_y_ = y; center_x_ = x; center_y_ = y;