mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-28 03:05:33 +00:00
Don't fail on lack of IfcAnnotation
This commit is contained in:
@@ -1586,103 +1586,106 @@ void SvgSerializer::addTextAnnotations(const drawing_key& k) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto annotations = file->instances_by_type("IfcAnnotation");
|
auto annotations = file->instances_by_type("IfcAnnotation");
|
||||||
for (auto& ann_ : *annotations) {
|
if (annotations) {
|
||||||
auto ann = (IfcUtil::IfcBaseEntity*) ann_;
|
for (auto& ann_ : *annotations) {
|
||||||
|
auto ann = (IfcUtil::IfcBaseEntity*) ann_;
|
||||||
|
|
||||||
auto ot = ann->get("ObjectType");
|
auto ot = ann->get("ObjectType");
|
||||||
auto nm = ann->get("Name");
|
auto nm = ann->get("Name");
|
||||||
auto ds = ann->get("Description");
|
auto ds = ann->get("Description");
|
||||||
auto pl = ann->get("ObjectPlacement");
|
auto pl = ann->get("ObjectPlacement");
|
||||||
|
|
||||||
if (!ot->isNull() && !nm->isNull() && !ds->isNull() && !pl->isNull()) {
|
if (!ot->isNull() && !nm->isNull() && !ds->isNull() && !pl->isNull()) {
|
||||||
auto object_type = (std::string) *ot;
|
auto object_type = (std::string) *ot;
|
||||||
auto name = (std::string) *nm;
|
auto name = (std::string) *nm;
|
||||||
auto desc = (std::string) *ds;
|
auto desc = (std::string) *ds;
|
||||||
|
|
||||||
if (object_type == "Text") {
|
if (object_type == "Text") {
|
||||||
IfcGeom::Kernel kernel(file);
|
IfcGeom::Kernel kernel(file);
|
||||||
gp_Trsf trsf;
|
gp_Trsf trsf;
|
||||||
if (kernel.convert_placement(*pl, trsf)) {
|
if (kernel.convert_placement(*pl, trsf)) {
|
||||||
|
|
||||||
auto v = trsf.TranslationPart();
|
|
||||||
if (k.first) {
|
|
||||||
v.ChangeCoord(1) *= -1.;
|
|
||||||
trsf.SetTranslationPart(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!range || (v.Z() >= range->first && v.Z() < range->second)) {
|
auto v = trsf.TranslationPart();
|
||||||
|
if (k.first) {
|
||||||
|
v.ChangeCoord(1) *= -1.;
|
||||||
|
trsf.SetTranslationPart(v);
|
||||||
|
}
|
||||||
|
|
||||||
if (meta.pln_3d.Position().Direction().Dot(gp_Dir(trsf.HVectorialPart().Column(3))) > 0.99) {
|
if (!range || (v.Z() >= range->first && v.Z() < range->second)) {
|
||||||
auto svg_name = nameElement(ann);
|
|
||||||
path_object* po;
|
|
||||||
if (k.first) {
|
|
||||||
po = &start_path(meta.pln_3d, k.first, svg_name);
|
|
||||||
} else {
|
|
||||||
po = &start_path(meta.pln_3d, k.second, svg_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (object_type.size()) {
|
if (meta.pln_3d.Position().Direction().Dot(gp_Dir(trsf.HVectorialPart().Column(3))) > 0.99) {
|
||||||
// postfix the object_type for CSS matching
|
auto svg_name = nameElement(ann);
|
||||||
boost::replace_all(svg_name, "class=\"IfcAnnotation\"", "class=\"IfcAnnotation " + object_type + "\"");
|
path_object* po;
|
||||||
}
|
if (k.first) {
|
||||||
|
po = &start_path(meta.pln_3d, k.first, svg_name);
|
||||||
boost::optional<double> font_size;
|
}
|
||||||
std::vector<std::string> tokens;
|
else {
|
||||||
boost::split(tokens, name, boost::is_any_of("_"));
|
po = &start_path(meta.pln_3d, k.second, svg_name);
|
||||||
if (tokens.size() == 2) {
|
|
||||||
try {
|
|
||||||
font_size = boost::lexical_cast<double>(tokens.back());
|
|
||||||
}
|
}
|
||||||
catch (...) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
// @todo column or row?
|
if (object_type.size()) {
|
||||||
double z_rotation = gp_Dir(trsf.HVectorialPart().Column(1)).AngleWithRef(gp_Dir(1., 0., 0.), gp_Dir(0., 0., 1.));
|
// postfix the object_type for CSS matching
|
||||||
z_rotation *= 180. / M_PI;
|
boost::replace_all(svg_name, "class=\"IfcAnnotation\"", "class=\"IfcAnnotation " + object_type + "\"");
|
||||||
|
}
|
||||||
|
|
||||||
util::string_buffer path;
|
boost::optional<double> font_size;
|
||||||
// dominant-baseline="central" is not well supported in IE.
|
std::vector<std::string> tokens;
|
||||||
// so we add a 0.35 offset to the dy of the tspans
|
boost::split(tokens, name, boost::is_any_of("_"));
|
||||||
path.add(" <text text-anchor=\"left\" x=\"");
|
if (tokens.size() == 2) {
|
||||||
xcoords.push_back(path.add(v.X()));
|
try {
|
||||||
path.add("\" y=\"");
|
font_size = boost::lexical_cast<double>(tokens.back());
|
||||||
ycoords.push_back(path.add(v.Y()));
|
}
|
||||||
|
catch (...) {}
|
||||||
|
}
|
||||||
|
|
||||||
path.add("\" transform=\"rotate(");
|
// @todo column or row?
|
||||||
path.add(z_rotation);
|
double z_rotation = gp_Dir(trsf.HVectorialPart().Column(1)).AngleWithRef(gp_Dir(1., 0., 0.), gp_Dir(0., 0., 1.));
|
||||||
path.add(" ");
|
z_rotation *= 180. / M_PI;
|
||||||
xcoords.push_back(path.add(v.X()));
|
|
||||||
path.add(" ");
|
|
||||||
ycoords.push_back(path.add(v.Y()));
|
|
||||||
path.add(")\"");
|
|
||||||
|
|
||||||
if (font_size) {
|
util::string_buffer path;
|
||||||
path.add(" font-size=\"");
|
// dominant-baseline="central" is not well supported in IE.
|
||||||
path.add(*font_size);
|
// so we add a 0.35 offset to the dy of the tspans
|
||||||
path.add("\"");
|
path.add(" <text text-anchor=\"left\" x=\"");
|
||||||
}
|
|
||||||
path.add(">");
|
|
||||||
|
|
||||||
std::vector<std::string> labels{ desc };
|
|
||||||
|
|
||||||
for (auto lit = labels.begin(); lit != labels.end(); ++lit) {
|
|
||||||
const auto& l = *lit;
|
|
||||||
double dy = labels.begin() == lit
|
|
||||||
? 0.0 // align bottom
|
|
||||||
: 1.0; // <- dy is relative to the previous text element, so
|
|
||||||
// always 1 for successive spans.
|
|
||||||
path.add("<tspan x=\"");
|
|
||||||
xcoords.push_back(path.add(v.X()));
|
xcoords.push_back(path.add(v.X()));
|
||||||
path.add("\" dy=\"");
|
path.add("\" y=\"");
|
||||||
path.add(boost::lexical_cast<std::string>(dy));
|
ycoords.push_back(path.add(v.Y()));
|
||||||
path.add("em\">");
|
|
||||||
path.add(l);
|
path.add("\" transform=\"rotate(");
|
||||||
path.add("</tspan>");
|
path.add(z_rotation);
|
||||||
|
path.add(" ");
|
||||||
|
xcoords.push_back(path.add(v.X()));
|
||||||
|
path.add(" ");
|
||||||
|
ycoords.push_back(path.add(v.Y()));
|
||||||
|
path.add(")\"");
|
||||||
|
|
||||||
|
if (font_size) {
|
||||||
|
path.add(" font-size=\"");
|
||||||
|
path.add(*font_size);
|
||||||
|
path.add("\"");
|
||||||
|
}
|
||||||
|
path.add(">");
|
||||||
|
|
||||||
|
std::vector<std::string> labels{ desc };
|
||||||
|
|
||||||
|
for (auto lit = labels.begin(); lit != labels.end(); ++lit) {
|
||||||
|
const auto& l = *lit;
|
||||||
|
double dy = labels.begin() == lit
|
||||||
|
? 0.0 // align bottom
|
||||||
|
: 1.0; // <- dy is relative to the previous text element, so
|
||||||
|
// always 1 for successive spans.
|
||||||
|
path.add("<tspan x=\"");
|
||||||
|
xcoords.push_back(path.add(v.X()));
|
||||||
|
path.add("\" dy=\"");
|
||||||
|
path.add(boost::lexical_cast<std::string>(dy));
|
||||||
|
path.add("em\">");
|
||||||
|
path.add(l);
|
||||||
|
path.add("</tspan>");
|
||||||
|
}
|
||||||
|
|
||||||
|
path.add("</text>");
|
||||||
|
|
||||||
|
po->second.push_back(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
path.add("</text>");
|
|
||||||
|
|
||||||
po->second.push_back(path);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user