Skip to content

Commit

Permalink
See #2894. Implement SVG mirroring options (typically used for RCPs o…
Browse files Browse the repository at this point in the history
…r useful when converting to other things like DXF).
  • Loading branch information
Moult committed Aug 11, 2023
1 parent a374ee3 commit a2b6f21
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/serializers/SvgSerializer.cpp
Expand Up @@ -761,7 +761,14 @@ void SvgSerializer::write(const geometry_data& data) {
// SVG has a coordinate system with the origin in the *upper*-left corner
// therefore we mirror the shape along the XZ-plane.
gp_Trsf trsf_mirror;
trsf_mirror.SetMirror(gp_Ax2(gp::Origin(), gp::DY()));
if (!mirror_y_) {
trsf_mirror.SetMirror(gp_Ax2(gp::Origin(), gp::DY()));
}
if (mirror_x_) {
gp_Trsf mirror_x;
mirror_x.SetMirror(gp_Ax2(gp::Origin(), gp::DX()));
trsf_mirror.PreMultiply(mirror_x);
}
BRepBuilderAPI_Transform make_transform_mirror(compound_unmirrored, trsf_mirror, true);
make_transform_mirror.Build();
// (When determinant < 0, copy is implied and the input is not mutated.)
Expand Down Expand Up @@ -1667,6 +1674,13 @@ std::array<std::array<double, 3>, 3> SvgSerializer::resize() {
cy = ymin * sc;
}

if (mirror_y_) {
cy = - size_->second - cy;
}
if (mirror_x_) {
cx = - size_->first - cx;
}

m = {{ {{sc,0,-cx}},{{0,sc,-cy}},{{0,0,1}} }};

float_item_list::const_iterator it;
Expand Down Expand Up @@ -1704,7 +1718,14 @@ void SvgSerializer::draw_hlr(const gp_Pln& pln, const drawing_key& drawing_name)
TopoDS_Shape hlr_compound;
if (drawing_name.first == nullptr) {
gp_Trsf trsf_mirror;
trsf_mirror.SetMirror(gp_Ax2(gp::Origin(), gp::DY()));
if (!mirror_y_) {
trsf_mirror.SetMirror(gp_Ax2(gp::Origin(), gp::DY()));
}
if (mirror_x_) {
gp_Trsf mirror_x;
mirror_x.SetMirror(gp_Ax2(gp::Origin(), gp::DX()));
trsf_mirror.PreMultiply(mirror_x);
}
BRepBuilderAPI_Transform make_transform_mirror(hlr_compound_unmirrored, trsf_mirror, true);
make_transform_mirror.Build();
hlr_compound = make_transform_mirror.Shape();
Expand Down
20 changes: 20 additions & 0 deletions src/serializers/SvgSerializer.h
Expand Up @@ -521,6 +521,8 @@ class SERIALIZERS_API SvgSerializer : public WriteOnlyGeometrySerializer {
bool emit_building_storeys_;
bool no_css_;
bool unify_inputs_;
bool mirror_y_;
bool mirror_x_;

int profile_threshold_;

Expand Down Expand Up @@ -572,6 +574,8 @@ class SERIALIZERS_API SvgSerializer : public WriteOnlyGeometrySerializer {
, polygonal_(false)
, emit_building_storeys_(true)
, no_css_(false)
, mirror_y_(false)
, mirror_x_(false)
, unify_inputs_(false)
, profile_threshold_(-1)
, file(0)
Expand Down Expand Up @@ -713,6 +717,22 @@ class SERIALIZERS_API SvgSerializer : public WriteOnlyGeometrySerializer {
return profile_threshold_;
}

void setMirrorY(bool b) {
mirror_y_ = b;
}

bool getMirrorY() const {
return mirror_y_;
}

void setMirrorX(bool b) {
mirror_x_ = b;
}

bool getMirrorX() const {
return mirror_x_;
}

protected:
std::string writeMetadata(const drawing_meta& m);
};
Expand Down

0 comments on commit a2b6f21

Please sign in to comment.