From 10ca307d986ab0c52faaab4fcaedb26bd42d1fd6 Mon Sep 17 00:00:00 2001 From: robnee Date: Sat, 6 Mar 2021 19:01:17 -0500 Subject: [PATCH] Add exportable option to default styles Primarily, this enables the user to export of construction entities in 2D views such as SVG. Previously constuction entities were always skipped. The "export these objects" is now available for all default styles. One may turn off export of constraints or the inactive groups for example. This also adds the exportable flag to the factory settings and support for saving the exportable option for default styles in the configuration. Construction entities with custom styles respect this option as well. NOTE: Running this version will add new entries to the configuration (Registry, .config etc.) on exit when testing this code. --- src/drawentity.cpp | 2 +- src/export.cpp | 1 - src/exportvector.cpp | 9 +++++++- src/sketch.h | 2 ++ src/style.cpp | 52 +++++++++++++++++++++++++------------------- 5 files changed, 41 insertions(+), 25 deletions(-) diff --git a/src/drawentity.cpp b/src/drawentity.cpp index b8e3cbd5..00bcb28a 100644 --- a/src/drawentity.cpp +++ b/src/drawentity.cpp @@ -462,7 +462,7 @@ void Entity::GenerateBezierCurves(SBezierList *sbl) const { // Record our style for all of the Beziers that we just created. for(; i < sbl->l.n; i++) { - sbl->l[i].auxA = style.v; + sbl->l[i].auxA = Style::ForEntity(h).v; } } diff --git a/src/export.cpp b/src/export.cpp index 0bf166f5..b9ebb914 100644 --- a/src/export.cpp +++ b/src/export.cpp @@ -207,7 +207,6 @@ void SolveSpaceUI::ExportViewOrWireframeTo(const Platform::Path &filename, bool for(auto &entity : SK.entity) { Entity *e = &entity; if(!e->IsVisible()) continue; - if(e->construction) continue; if(SS.exportPwlCurves || sm || fabs(SS.exportOffset) > LENGTH_EPS) { diff --git a/src/exportvector.cpp b/src/exportvector.cpp index 198502c1..97730997 100644 --- a/src/exportvector.cpp +++ b/src/exportvector.cpp @@ -1085,7 +1085,9 @@ void SvgFileWriter::StartFile() { fprintf(f, "}\r\n"); auto export_style = [&](hStyle hs) { + Style *s = Style::Get(hs); RgbaColor strokeRgb = Style::Color(hs, /*forExport=*/true); + RgbaColor fillRgb = Style::FillColor(hs, /*forExport=*/true); StipplePattern pattern = Style::PatternType(hs); double stippleScale = Style::StippleScaleMm(hs); @@ -1100,7 +1102,12 @@ void SvgFileWriter::StartFile() { if(!patternStr.empty()) { fprintf(f, "stroke-dasharray:%s;\r\n", patternStr.c_str()); } - fprintf(f, "fill:none;\r\n"); + if(s->filled) { + fprintf(f, "fill:#%02x%02x%02x;\r\n", fillRgb.red, fillRgb.green, fillRgb.blue); + } + else { + fprintf(f, "fill:none;\r\n"); + } fprintf(f, "}\r\n"); }; diff --git a/src/sketch.h b/src/sketch.h index 903e638f..68a912b3 100644 --- a/src/sketch.h +++ b/src/sketch.h @@ -883,6 +883,7 @@ public: RgbaColor color; double width; int zIndex; + bool exportable; } Default; static const Default Defaults[]; @@ -890,6 +891,7 @@ public: static std::string CnfWidth(const std::string &prefix); static std::string CnfTextHeight(const std::string &prefix); static std::string CnfPrefixToName(const std::string &prefix); + static std::string CnfExportable(const std::string &prefix); static void CreateAllDefaultStyles(); static void CreateDefaultStyle(hStyle h); diff --git a/src/style.cpp b/src/style.cpp index 1f719f67..19a1835c 100644 --- a/src/style.cpp +++ b/src/style.cpp @@ -8,22 +8,22 @@ #include "solvespace.h" const Style::Default Style::Defaults[] = { - { { ACTIVE_GRP }, "ActiveGrp", RGBf(1.0, 1.0, 1.0), 1.5, 4 }, - { { CONSTRUCTION }, "Construction", RGBf(0.1, 0.7, 0.1), 1.5, 0 }, - { { INACTIVE_GRP }, "InactiveGrp", RGBf(0.5, 0.3, 0.0), 1.5, 3 }, - { { DATUM }, "Datum", RGBf(0.0, 0.8, 0.0), 1.5, 0 }, - { { SOLID_EDGE }, "SolidEdge", RGBf(0.8, 0.8, 0.8), 1.0, 2 }, - { { CONSTRAINT }, "Constraint", RGBf(1.0, 0.1, 1.0), 1.0, 0 }, - { { SELECTED }, "Selected", RGBf(1.0, 0.0, 0.0), 1.5, 0 }, - { { HOVERED }, "Hovered", RGBf(1.0, 1.0, 0.0), 1.5, 0 }, - { { CONTOUR_FILL }, "ContourFill", RGBf(0.0, 0.1, 0.1), 1.0, 0 }, - { { NORMALS }, "Normals", RGBf(0.0, 0.4, 0.4), 1.0, 0 }, - { { ANALYZE }, "Analyze", RGBf(0.0, 1.0, 1.0), 3.0, 0 }, - { { DRAW_ERROR }, "DrawError", RGBf(1.0, 0.0, 0.0), 8.0, 0 }, - { { DIM_SOLID }, "DimSolid", RGBf(0.1, 0.1, 0.1), 1.0, 0 }, - { { HIDDEN_EDGE }, "HiddenEdge", RGBf(0.8, 0.8, 0.8), 1.0, 1 }, - { { OUTLINE }, "Outline", RGBf(0.8, 0.8, 0.8), 3.0, 5 }, - { { 0 }, NULL, RGBf(0.0, 0.0, 0.0), 0.0, 0 } + { { ACTIVE_GRP }, "ActiveGrp", RGBf(1.0, 1.0, 1.0), 1.5, 4, true }, + { { CONSTRUCTION }, "Construction", RGBf(0.1, 0.7, 0.1), 1.5, 0, false }, + { { INACTIVE_GRP }, "InactiveGrp", RGBf(0.5, 0.3, 0.0), 1.5, 3, true }, + { { DATUM }, "Datum", RGBf(0.0, 0.8, 0.0), 1.5, 0, true }, + { { SOLID_EDGE }, "SolidEdge", RGBf(0.8, 0.8, 0.8), 1.0, 2, true }, + { { CONSTRAINT }, "Constraint", RGBf(1.0, 0.1, 1.0), 1.0, 0, true }, + { { SELECTED }, "Selected", RGBf(1.0, 0.0, 0.0), 1.5, 0, true }, + { { HOVERED }, "Hovered", RGBf(1.0, 1.0, 0.0), 1.5, 0, true }, + { { CONTOUR_FILL }, "ContourFill", RGBf(0.0, 0.1, 0.1), 1.0, 0, true }, + { { NORMALS }, "Normals", RGBf(0.0, 0.4, 0.4), 1.0, 0, true }, + { { ANALYZE }, "Analyze", RGBf(0.0, 1.0, 1.0), 3.0, 0, true }, + { { DRAW_ERROR }, "DrawError", RGBf(1.0, 0.0, 0.0), 8.0, 0, true }, + { { DIM_SOLID }, "DimSolid", RGBf(0.1, 0.1, 0.1), 1.0, 0, true }, + { { HIDDEN_EDGE }, "HiddenEdge", RGBf(0.8, 0.8, 0.8), 1.0, 1, true }, + { { OUTLINE }, "Outline", RGBf(0.8, 0.8, 0.8), 3.0, 5, true }, + { { 0 }, NULL, RGBf(0.0, 0.0, 0.0), 0.0, 0, true } }; std::string Style::CnfColor(const std::string &prefix) { @@ -35,6 +35,9 @@ std::string Style::CnfWidth(const std::string &prefix) { std::string Style::CnfTextHeight(const std::string &prefix) { return "Style_" + prefix + "_TextHeight"; } +std::string Style::CnfExportable(const std::string &prefix) { + return "Style_" + prefix + "_Exportable"; +} std::string Style::CnfPrefixToName(const std::string &prefix) { std::string name = "#def-"; @@ -97,7 +100,9 @@ void Style::FillDefaultStyle(Style *s, const Default *d, bool factory) { s->textOrigin = TextOrigin::NONE; s->textAngle = 0; s->visible = true; - s->exportable = true; + s->exportable = (factory) + ? d->exportable + : settings->ThawBool(CnfExportable(d->cnfPrefix), d->exportable); s->filled = false; s->fillColor = RGBf(0.3, 0.3, 0.3); s->stippleType = (d->h.v == Style::HIDDEN_EDGE) ? StipplePattern::DASH @@ -121,6 +126,7 @@ void Style::FreezeDefaultStyles(Platform::SettingsRef settings) { settings->FreezeColor(CnfColor(d->cnfPrefix), Color(d->h)); settings->FreezeFloat(CnfWidth(d->cnfPrefix), (float)Width(d->h)); settings->FreezeFloat(CnfTextHeight(d->cnfPrefix), (float)TextHeight(d->h)); + settings->FreezeBool(CnfExportable(d->cnfPrefix), Exportable(d->h.v)); } } @@ -850,17 +856,19 @@ void TextWindow::ShowStyleInfo() { ((uint32_t)s->textOrigin & (uint32_t)Style::TextOrigin::TOP) ? RADIO_TRUE : RADIO_FALSE); } - if(s->h.v >= Style::FIRST_CUSTOM) { - Printf(false, ""); + Printf(false, ""); + if(s->h.v >= Style::FIRST_CUSTOM) { Printf(false, " %Fd%D%f%Lv%s show these objects on screen%E", s->h.v, &ScreenChangeStyleYesNo, s->visible ? CHECK_TRUE : CHECK_FALSE); + } - Printf(false, " %Fd%D%f%Le%s export these objects%E", - s->h.v, &ScreenChangeStyleYesNo, - s->exportable ? CHECK_TRUE : CHECK_FALSE); + Printf(false, " %Fd%D%f%Le%s export these objects%E", + s->h.v, &ScreenChangeStyleYesNo, + s->exportable ? CHECK_TRUE : CHECK_FALSE); + if(s->h.v >= Style::FIRST_CUSTOM) { Printf(false, ""); Printf(false, "To assign lines or curves to this style,"); Printf(false, "right-click them on the drawing.");