mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-11 06:18:09 +00:00
Support writing SVG to scale
This commit is contained in:
@@ -706,17 +706,21 @@ void SvgSerializer::finalize() {
|
||||
const double dx = xmax - xmin;
|
||||
const double dy = ymax - ymin;
|
||||
|
||||
double sc = 1.;
|
||||
|
||||
if (dx / width > dy / height) {
|
||||
sc = width / dx;
|
||||
double sc, cx, cy;
|
||||
if (scale_) {
|
||||
sc = (*scale_) * 1000;
|
||||
cx = (xmax + xmin) / 2. * sc - width / 2.;
|
||||
cy = (ymax + ymin) / 2. * sc - height / 2.;
|
||||
} else {
|
||||
sc = height / dy;
|
||||
if (dx / width > dy / height) {
|
||||
sc = width / dx;
|
||||
} else {
|
||||
sc = height / dy;
|
||||
}
|
||||
cx = xmin * sc;
|
||||
cy = ymin * sc;
|
||||
}
|
||||
|
||||
const double cx = xmin * sc;
|
||||
const double cy = ymin * sc;
|
||||
|
||||
{std::vector< boost::shared_ptr<util::string_buffer::float_item> >::const_iterator it;
|
||||
for (it = xcoords.begin(); it != xcoords.end(); ++it) {
|
||||
double& v = (*it)->value();
|
||||
@@ -760,7 +764,15 @@ void SvgSerializer::finalize() {
|
||||
}
|
||||
|
||||
void SvgSerializer::writeHeader() {
|
||||
svg_file << "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n"
|
||||
svg_file << "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"";
|
||||
if (scale_) {
|
||||
svg_file <<
|
||||
" width=\"" << width << "mm\""
|
||||
" height=\"" << height << "mm\"" <<
|
||||
" viewBox=\"0 0 " << width << " " << height << "\"";
|
||||
}
|
||||
|
||||
svg_file << ">\n"
|
||||
" <defs>\n"
|
||||
" <marker id=\"arrowend\" markerWidth=\"10\" markerHeight=\"7\" refX=\"10\" refY=\"3.5\" orient=\"auto\">\n"
|
||||
" <polygon points=\"0 0, 10 3.5, 0 7\" />\n"
|
||||
@@ -774,7 +786,16 @@ void SvgSerializer::writeHeader() {
|
||||
" .IfcAnnotation path {\n"
|
||||
" marker-end: url(#arrowend);\n"
|
||||
" marker-start: url(#arrowstart);\n"
|
||||
" }\n"
|
||||
" }\n";
|
||||
|
||||
if (scale_) {
|
||||
svg_file <<
|
||||
" text {\n" // (pt) (px) (in) (mm)
|
||||
" font-size: 4;\n" // approx 12 / 0.75 / 96 * 25.4
|
||||
" }\n";
|
||||
}
|
||||
|
||||
svg_file <<
|
||||
" ]]>\n"
|
||||
" </style>\n";
|
||||
}
|
||||
|
||||
@@ -73,6 +73,7 @@ protected:
|
||||
std::ofstream svg_file;
|
||||
double xmin, ymin, xmax, ymax, width, height;
|
||||
boost::optional<std::vector<std::pair<std::pair<double, double>, IfcUtil::IfcBaseEntity*>>> section_heights;
|
||||
boost::optional<double> scale_;
|
||||
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::vector< boost::shared_ptr<util::string_buffer::float_item> > xcoords;
|
||||
@@ -90,6 +91,9 @@ public:
|
||||
, ymax(-std::numeric_limits<double>::infinity())
|
||||
, with_section_heights_from_storey_(false)
|
||||
, rescale(false)
|
||||
, print_space_names_(false)
|
||||
, print_space_areas_(false)
|
||||
, draw_door_arcs_(false)
|
||||
, file(0)
|
||||
, storey_(0)
|
||||
{}
|
||||
@@ -113,6 +117,7 @@ public:
|
||||
void setPrintSpaceNames(bool b) { print_space_names_ = b; }
|
||||
void setPrintSpaceAreas(bool b) { print_space_areas_ = b; }
|
||||
void setDrawDoorArcs(bool b) { draw_door_arcs_ = b; }
|
||||
void setScale(double s) { scale_ = s; }
|
||||
std::string nameElement(const IfcUtil::IfcBaseEntity* storey, const IfcGeom::Element<real_t>* elem);
|
||||
std::string nameElement(const IfcUtil::IfcBaseEntity* elem);
|
||||
std::string idElement(const IfcUtil::IfcBaseEntity* elem);
|
||||
|
||||
Reference in New Issue
Block a user