From e7afb49bd67284227bf5df1df22f9993b1bfa581 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 21 Jul 2016 21:05:55 +0200 Subject: =?UTF-8?q?This=20for=20you=20CR=20=C2=B7=20Measure=20line,=20show?= =?UTF-8?q?=20the=20distance=20on=20rect=20lines=20CAD=20like=20with=20aut?= =?UTF-8?q?o=20update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (bzr r15017.1.1) --- src/live_effects/CMakeLists.txt | 4 + src/live_effects/Makefile_insert | 2 + src/live_effects/effect-enum.h | 1 + src/live_effects/effect.cpp | 6 ++ src/live_effects/lpe-measure-line.cpp | 45 +++++++++++ src/live_effects/lpe-measure-line.h | 48 ++++++++++++ src/live_effects/parameter/texttopath.cpp | 125 ++++++++++++++++++++++++++++++ src/live_effects/parameter/texttopath.h | 87 +++++++++++++++++++++ 8 files changed, 318 insertions(+) create mode 100644 src/live_effects/lpe-measure-line.cpp create mode 100644 src/live_effects/lpe-measure-line.h create mode 100644 src/live_effects/parameter/texttopath.cpp create mode 100644 src/live_effects/parameter/texttopath.h (limited to 'src/live_effects') diff --git a/src/live_effects/CMakeLists.txt b/src/live_effects/CMakeLists.txt index 9a2f06a76..ed66dd2d9 100644 --- a/src/live_effects/CMakeLists.txt +++ b/src/live_effects/CMakeLists.txt @@ -27,6 +27,7 @@ set(live_effects_SRC lpe-lattice.cpp lpe-lattice2.cpp lpe-line_segment.cpp + lpe-measure-line.cpp lpe-mirror_symmetry.cpp lpe-offset.cpp lpe-parallel.cpp @@ -68,6 +69,7 @@ set(live_effects_SRC parameter/powerstrokepointarray.cpp parameter/random.cpp parameter/text.cpp + parameter/texttopath.cpp parameter/togglebutton.cpp parameter/transformedpoint.cpp parameter/unit.cpp @@ -105,6 +107,7 @@ set(live_effects_SRC lpe-lattice.h lpe-lattice2.h lpe-line_segment.h + lpe-measure-line.h lpe-mirror_symmetry.h lpe-offset.h lpe-parallel.h @@ -148,6 +151,7 @@ set(live_effects_SRC parameter/powerstrokepointarray.h parameter/random.h parameter/text.h + parameter/texttopath.h parameter/togglebutton.h parameter/transformedpoint.h parameter/unit.h diff --git a/src/live_effects/Makefile_insert b/src/live_effects/Makefile_insert index b5bee55c8..d227d379d 100644 --- a/src/live_effects/Makefile_insert +++ b/src/live_effects/Makefile_insert @@ -70,6 +70,8 @@ ink_common_sources += \ live_effects/lpe-perspective_path.h \ live_effects/lpe-perspective-envelope.cpp \ live_effects/lpe-perspective-envelope.h \ + live_effects/lpe-measure-line.cpp \ + live_effects/lpe-measure-line.h \ live_effects/lpe-mirror_symmetry.cpp \ live_effects/lpe-mirror_symmetry.h \ live_effects/lpe-circle_3pts.cpp \ diff --git a/src/live_effects/effect-enum.h b/src/live_effects/effect-enum.h index eea26184c..3682aa1bd 100644 --- a/src/live_effects/effect-enum.h +++ b/src/live_effects/effect-enum.h @@ -36,6 +36,7 @@ enum EffectType { CONSTRUCT_GRID, PERP_BISECTOR, TANGENT_TO_CURVE, + MEASURE_LINE, MIRROR_SYMMETRY, CIRCLE_3PTS, TRANSFORM_2PTS, diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 1868ca43b..d01312ca7 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -40,6 +40,7 @@ #include "live_effects/lpe-lattice2.h" #include "live_effects/lpe-lattice.h" #include "live_effects/lpe-line_segment.h" +#include "live_effects/lpe-measure-line.h" #include "live_effects/lpe-mirror_symmetry.h" #include "live_effects/lpe-offset.h" #include "live_effects/lpe-parallel.h" @@ -151,6 +152,8 @@ const Util::EnumData LPETypeData[] = { {FILL_BETWEEN_MANY, N_("Fill between many"), "fill_between_many"}, {ELLIPSE_5PTS, N_("Ellipse by 5 points"), "ellipse_5pts"}, {BOUNDING_BOX, N_("Bounding Box"), "bounding_box"}, +/* 9.93 */ + {MEASURE_LINE, N_("Measure Line"), "measure-line"}, }; const Util::EnumDataConverter LPETypeConverter(LPETypeData, sizeof(LPETypeData)/sizeof(*LPETypeData)); @@ -319,6 +322,9 @@ Effect::New(EffectType lpenr, LivePathEffectObject *lpeobj) case TRANSFORM_2PTS: neweffect = static_cast ( new LPETransform2Pts(lpeobj) ); break; + case MEASURE_LINE: + neweffect = static_cast ( new LPEMeasureLine(lpeobj) ); + break; default: g_warning("LivePathEffect::Effect::New called with invalid patheffect type (%d)", lpenr); neweffect = NULL; diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp new file mode 100644 index 000000000..d6fe02afd --- /dev/null +++ b/src/live_effects/lpe-measure-line.cpp @@ -0,0 +1,45 @@ +/* + * Author(s): + * Jabiertxo Arraiza Cenoz + * + * Copyright (C) 2014 Author(s) + + * Released under GNU GPL, read the file 'COPYING' for more information + */ +#include "live_effects/lpe-measure-line.h" + +// TODO due to internal breakage in glibmm headers, this must be last: +#include + +using namespace Geom; +namespace Inkscape { +namespace LivePathEffect { + +LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : + Effect(lpeobject), + text(_("text:"), _("text"), "text", &wr, this, "This is a labelXXX") +{ + registerParameter(&text); +} + +LPEMeasureLine::~LPEMeasureLine() {} + +Geom::PathVector +LPEMeasureLine::doEffect_path(Geom::PathVector const &path_in) +{ + return path_in; +} + +}; //namespace LivePathEffect +}; /* namespace Inkscape */ + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offset:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h new file mode 100644 index 000000000..5ba1ff8c6 --- /dev/null +++ b/src/live_effects/lpe-measure-line.h @@ -0,0 +1,48 @@ +#ifndef INKSCAPE_LPE_MEASURE_LINE_H +#define INKSCAPE_LPE_MEASURE_LINE_H + +/* + * Author(s): + * Jabiertxo Arraiza Cenoz + * + * Copyright (C) 2014 Author(s) + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ +#include "live_effects/parameter/texttopath.h" +#include "live_effects/effect.h" + +namespace Inkscape { +namespace LivePathEffect { + +class LPEMeasureLine : public Effect { +public: + LPEMeasureLine(LivePathEffectObject *lpeobject); + virtual ~LPEMeasureLine(); + + virtual Geom::PathVector doEffect_path(Geom::PathVector const &path_in); + +private: + + TextToPathParam text; + + LPEMeasureLine(const LPEMeasureLine &); + LPEMeasureLine &operator=(const LPEMeasureLine &); + +}; + +} //namespace LivePathEffect +} //namespace Inkscape + +#endif + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/live_effects/parameter/texttopath.cpp b/src/live_effects/parameter/texttopath.cpp new file mode 100644 index 000000000..8625e4d71 --- /dev/null +++ b/src/live_effects/parameter/texttopath.cpp @@ -0,0 +1,125 @@ +/* + * Copyright (C) Maximilian Albert 2008 + * + * Authors: + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "ui/widget/registered-widget.h" +#include + +#include "live_effects/parameter/texttopath.h" +#include "live_effects/effect.h" +#include "svg/svg.h" +#include "svg/stringstream.h" +#include "widgets/icon.h" +#include "inkscape.h" +#include "verbs.h" +#include "display/canvas-text.h" + +#include <2geom/sbasis-geometric.h> + +namespace Inkscape { + +namespace LivePathEffect { + +TextToPathParam::TextToPathParam( const Glib::ustring& label, const Glib::ustring& tip, + const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, + Effect* effect, const Glib::ustring default_value ) + : Parameter(label, tip, key, wr, effect), + value(default_value), + defvalue(default_value) +{ + SPDesktop *desktop = SP_ACTIVE_DESKTOP; // FIXME: we shouldn't use this! + canvas_text = (SPCanvasText *) sp_canvastext_new(desktop->getTempGroup(), desktop, Geom::Point(0,0), ""); + sp_canvastext_set_text (canvas_text, default_value.c_str()); + sp_canvastext_set_coords (canvas_text, 0, 0); +} + +void +TextToPathParam::param_set_default() +{ + param_setValue(defvalue); +} + +void +TextToPathParam::setPos(Geom::Point pos) +{ + sp_canvastext_set_coords (canvas_text, pos); +} + +void +TextToPathParam::setPosAndAnchor(const Geom::Piecewise > &pwd2, + const double t, const double length, bool /*use_curvature*/) +{ + using namespace Geom; + + Piecewise > pwd2_reparam = arc_length_parametrization(pwd2, 2 , 0.1); + double t_reparam = pwd2_reparam.cuts.back() * t; + Point pos = pwd2_reparam.valueAt(t_reparam); + Point dir = unit_vector(derivative(pwd2_reparam).valueAt(t_reparam)); + Point n = -rot90(dir); + double angle = Geom::angle_between(dir, Point(1,0)); + + sp_canvastext_set_coords(canvas_text, pos + n * length); + sp_canvastext_set_anchor_manually(canvas_text, std::sin(angle), -std::cos(angle)); +} + +void +TextToPathParam::setAnchor(double x_value, double y_value) +{ + anchor_x = x_value; + anchor_y = y_value; + sp_canvastext_set_anchor_manually (canvas_text, anchor_x, anchor_y); +} + +bool +TextToPathParam::param_readSVGValue(const gchar * strvalue) +{ + param_setValue(strvalue); + return true; +} + +gchar * +TextToPathParam::param_getSVGValue() const +{ + return g_strdup(value.c_str()); +} + +Gtk::Widget * +TextToPathParam::param_newWidget() +{ + Inkscape::UI::Widget::RegisteredText *rsu = Gtk::manage(new Inkscape::UI::Widget::RegisteredText( + param_label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc())); + + rsu->setText(value.c_str()); + rsu->setProgrammatically = false; + + rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change text parameter")); + + return dynamic_cast (rsu); +} + +void +TextToPathParam::param_setValue(const Glib::ustring newvalue) +{ + value = newvalue; + + sp_canvastext_set_text (canvas_text, newvalue.c_str()); +} + +} /* namespace LivePathEffect */ + +} /* namespace Inkscape */ + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/live_effects/parameter/texttopath.h b/src/live_effects/parameter/texttopath.h new file mode 100644 index 000000000..9a0ee38e2 --- /dev/null +++ b/src/live_effects/parameter/texttopath.h @@ -0,0 +1,87 @@ +#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_TEXT_TO_PATH_H +#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_TEXT_TO_PATH_H + +/* + * Inkscape::LivePathEffectParameters + * + * Authors: + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include + +#include "display/canvas-bpath.h" +#include "live_effects/parameter/parameter.h" + +struct SPCanvasText; + +namespace Inkscape { + +namespace LivePathEffect { + +class TextToPathParam : public Parameter { +public: + TextToPathParam( const Glib::ustring& label, + const Glib::ustring& tip, + const Glib::ustring& key, + Inkscape::UI::Widget::Registry* wr, + Effect* effect, + const Glib::ustring default_value = ""); + virtual ~TextToPathParam() {} + + virtual Gtk::Widget * param_newWidget(); + + virtual bool param_readSVGValue(const gchar * strvalue); + virtual gchar * param_getSVGValue() const; + + void param_setValue(const Glib::ustring newvalue); + virtual void param_set_default(); + void setPos(Geom::Point pos); + void setPosAndAnchor(const Geom::Piecewise > &pwd2, + const double t, const double length, bool use_curvature = false); + void setAnchor(double x_value, double y_value); + + const Glib::ustring get_value() const { return defvalue; }; + +private: + TextToPathParam(const TextToPathParam&); + TextToPathParam& operator=(const TextToPathParam&); + double anchor_x; + double anchor_y; + + Glib::ustring value; + Glib::ustring defvalue; + + SPCanvasText *canvas_text; +}; + +/* + * This parameter does not display a widget in the LPE dialog; LPEs can use it to display on-canvas + * text that should not be settable by the user. Note that since no widget is provided, the + * parameter must be initialized differently than usual (only with a pointer to the parent effect; + * no label, no tooltip, etc.). + */ +class TextToPathParamInternal : public TextToPathParam { +public: + TextToPathParamInternal(Effect* effect) : + TextToPathParam("", "", "", NULL, effect) {} + + virtual Gtk::Widget * param_newWidget() { return NULL; } +}; + +} //namespace LivePathEffect + +} //namespace Inkscape + +#endif + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : -- cgit v1.2.3 From a5d6c9a27683820be3d84eea73c2d6f161ce0e8e Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 24 Jul 2016 18:49:11 +0200 Subject: Add Text tag and update widgets code (bzr r15017.1.2) --- src/live_effects/CMakeLists.txt | 4 +- src/live_effects/effect.cpp | 3 +- src/live_effects/effect.h | 1 + src/live_effects/lpe-measure-line.cpp | 91 +++++++++++++++++++- src/live_effects/lpe-measure-line.h | 15 ++-- src/live_effects/lpe-transform_2pts.cpp | 1 - src/live_effects/parameter/font.cpp | 126 ++++++++++++++++++++++++++++ src/live_effects/parameter/font.h | 77 +++++++++++++++++ src/live_effects/parameter/point.cpp | 2 +- src/live_effects/parameter/point.h | 1 - src/live_effects/parameter/texttopath.cpp | 125 --------------------------- src/live_effects/parameter/texttopath.h | 87 ------------------- src/live_effects/parameter/togglebutton.cpp | 8 ++ 13 files changed, 315 insertions(+), 226 deletions(-) create mode 100644 src/live_effects/parameter/font.cpp create mode 100644 src/live_effects/parameter/font.h delete mode 100644 src/live_effects/parameter/texttopath.cpp delete mode 100644 src/live_effects/parameter/texttopath.h (limited to 'src/live_effects') diff --git a/src/live_effects/CMakeLists.txt b/src/live_effects/CMakeLists.txt index ed66dd2d9..c3d740862 100644 --- a/src/live_effects/CMakeLists.txt +++ b/src/live_effects/CMakeLists.txt @@ -69,7 +69,7 @@ set(live_effects_SRC parameter/powerstrokepointarray.cpp parameter/random.cpp parameter/text.cpp - parameter/texttopath.cpp + parameter/font.cpp parameter/togglebutton.cpp parameter/transformedpoint.cpp parameter/unit.cpp @@ -151,7 +151,7 @@ set(live_effects_SRC parameter/powerstrokepointarray.h parameter/random.h parameter/text.h - parameter/texttopath.h + parameter/font.h parameter/togglebutton.h parameter/transformedpoint.h parameter/unit.h diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index d01312ca7..a62e8b62b 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -370,6 +370,7 @@ Effect::Effect(LivePathEffectObject *lpeobject) concatenate_before_pwd2(false), sp_lpe_item(NULL), current_zoom(1), + upd_params(true), sp_curve(NULL), provides_own_flash_paths(true), // is automatically set to false if providesOwnFlashPaths() is not overridden is_ready(false) // is automatically set to false if providesOwnFlashPaths() is not overridden @@ -697,7 +698,7 @@ Effect::newWidget() ++it; } - + upd_params = false; return dynamic_cast(vbox); } diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index 898e089b7..e0a7cbe6b 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -122,6 +122,7 @@ public: void editNextParamOncanvas(SPItem * item, SPDesktop * desktop); bool apply_to_clippath_and_mask; + bool upd_params; protected: Effect(LivePathEffectObject *lpeobject); diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index d6fe02afd..7b823b072 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -7,6 +7,11 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ #include "live_effects/lpe-measure-line.h" +#include "inkscape.h" +#include "uri.h" +#include "uri-references.h" +#include "desktop.h" +#include "document.h" // TODO due to internal breakage in glibmm headers, this must be last: #include @@ -17,16 +22,98 @@ namespace LivePathEffect { LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : Effect(lpeobject), - text(_("text:"), _("text"), "text", &wr, this, "This is a labelXXX") + fontselector(_("Font Selector:"), _("Font Selector"), "fontselector", &wr, this, " ") { - registerParameter(&text); + registerParameter(&fontselector); + rtext = NULL; + fontlister = Inkscape::FontLister::get_instance(); } LPEMeasureLine::~LPEMeasureLine() {} +void +LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) +{ + if (SP_ACTIVE_DESKTOP) { + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_mlsize").c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + Inkscape::XML::Node *rtspan = NULL; + if (elemref = SVGElemRef->getObject()) { + rtext = elemref->getRepr(); + sp_repr_set_svg_double(rtext, "x", 0); + sp_repr_set_svg_double(rtext, "y", 0); + } else { + rtext = xml_doc->createElement("svg:text"); + rtext->setAttribute("xml:space", "preserve"); + rtext->setAttribute("id", ((Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_mlsize").c_str()); + /* Set style */ + sp_repr_set_svg_double(rtext, "x", 0); + sp_repr_set_svg_double(rtext, "y", 0); + /* Create */ + rtspan = xml_doc->createElement("svg:tspan"); + rtspan->setAttribute("sodipodi:role", "line"); + } + SPCSSAttr *css = sp_repr_css_attr_new(); + Glib::ustring fontspec = fontselector.param_readFontSpec(fontselector.param_getSVGValue()); + double fontsize = fontselector.param_readFontSize(fontselector.param_getSVGValue()); + fontlister->fill_css( css, fontspec ); + std::stringstream font_size; + font_size.imbue(std::locale::classic()); + font_size << fontsize << "pt"; + sp_repr_css_set_property (css, "font-size", font_size.str().c_str()); + sp_repr_css_set_property (css, "font-style", "normal"); + sp_repr_css_set_property (css, "font-weight", "normal"); + sp_repr_css_set_property (css, "line-height", "125%"); + sp_repr_css_set_property (css, "letter-spacing", "0"); + sp_repr_css_set_property (css, "word-spacing", "0"); + sp_repr_css_set_property (css, "text-align", "center"); + sp_repr_css_set_property (css, "text-anchor", "middle"); + sp_repr_css_set_property (css, "fill", "#000000"); + sp_repr_css_set_property (css, "fill-opacity", "1"); + sp_repr_css_set_property (css, "stroke", "none"); + Glib::ustring css_str; + sp_repr_css_write_string(css,css_str); + if (!rtspan) { + rtspan = rtext->firstChild(); + } + rtspan->setAttribute("style", css_str.c_str()); + sp_repr_css_attr_unref (css); + if (!elemref) { + rtext->addChild(rtspan, NULL); + Inkscape::GC::release(rtspan); + } + /* Create TEXT */ + std::stringstream lenghtstr; + lenghtstr.imbue(std::locale::classic()); + lenghtstr << lenght; + Inkscape::XML::Node *rstring = NULL; + if (!elemref) { + rstring = xml_doc->createTextNode(lenghtstr.str().c_str()); + rtspan->addChild(rstring, NULL); + Inkscape::GC::release(rstring); + } else { + rstring = rtspan->firstChild(); + rstring->setContent(lenghtstr.str().c_str()); + } + SPObject * text_obj = NULL; + if (!elemref) { + text_obj = SP_OBJECT(desktop->currentLayer()->appendChildRepr(rtext)); + Inkscape::GC::release(rtext); + } else { + text_obj = desktop->currentLayer()->get_child_by_repr(rtext); + } + text_obj->updateRepr(); + } +} + Geom::PathVector LPEMeasureLine::doEffect_path(Geom::PathVector const &path_in) { + lenght = Geom::distance(path_in.initialPoint(), path_in.finalPoint()); return path_in; } diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index 5ba1ff8c6..7e576ffe6 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -9,8 +9,11 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ -#include "live_effects/parameter/texttopath.h" +#include "live_effects/parameter/font.h" #include "live_effects/effect.h" +#include +#include "xml/node.h" + namespace Inkscape { namespace LivePathEffect { @@ -19,13 +22,13 @@ class LPEMeasureLine : public Effect { public: LPEMeasureLine(LivePathEffectObject *lpeobject); virtual ~LPEMeasureLine(); - + virtual void doBeforeEffect (SPLPEItem const* lpeitem); virtual Geom::PathVector doEffect_path(Geom::PathVector const &path_in); - private: - - TextToPathParam text; - + double lenght; + FontParam fontselector; + Inkscape::FontLister *fontlister; + Inkscape::XML::Node *rtext; LPEMeasureLine(const LPEMeasureLine &); LPEMeasureLine &operator=(const LPEMeasureLine &); diff --git a/src/live_effects/lpe-transform_2pts.cpp b/src/live_effects/lpe-transform_2pts.cpp index 3c4ce0708..d32cf42fc 100644 --- a/src/live_effects/lpe-transform_2pts.cpp +++ b/src/live_effects/lpe-transform_2pts.cpp @@ -90,7 +90,6 @@ LPETransform2Pts::doOnApply(SPLPEItem const* lpeitem) { using namespace Geom; original_bbox(lpeitem); - point_a = Point(boundingbox_X.min(), boundingbox_Y.middle()); point_b = Point(boundingbox_X.max(), boundingbox_Y.middle()); SPLPEItem * splpeitem = const_cast(lpeitem); diff --git a/src/live_effects/parameter/font.cpp b/src/live_effects/parameter/font.cpp new file mode 100644 index 000000000..174b66152 --- /dev/null +++ b/src/live_effects/parameter/font.cpp @@ -0,0 +1,126 @@ +/* + * Authors: + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + + +#include "ui/widget/registered-widget.h" +#include "live_effects/parameter/font.h" +#include "live_effects/effect.h" +#include "ui/widget/font-selector.h" +#include "svg/svg.h" +#include "svg/stringstream.h" +#include "verbs.h" + +#include + +namespace Inkscape { + +namespace LivePathEffect { + +FontParam::FontParam( const Glib::ustring& label, const Glib::ustring& tip, + const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, + Effect* effect, const Glib::ustring default_value ) + : Parameter(label, tip, key, wr, effect), + value(default_value), + defvalue(default_value) +{ +} + +void +FontParam::param_set_default() +{ + param_setValue(defvalue); +} + + +Glib::ustring +FontParam::param_readFontSpec(const gchar * strvalue) +{ + Glib::ustring result; + gchar ** strarray = g_strsplit(strvalue, " @ ", 2); + double fontsize; + if (strarray[1]) { + unsigned int success = sp_svg_number_read_d(strarray[1], &fontsize); + if (success == 1) { + result = (Glib::ustring)strarray[0]; + g_strfreev (strarray); + return result; + } + } + g_strfreev (strarray); + return result; +} + +double +FontParam::param_readFontSize(const gchar * strvalue) +{ + gchar ** strarray = g_strsplit(strvalue, " @ ", 2); + double fontsize = 0; + if (strarray[1]) { + unsigned int success = sp_svg_number_read_d(strarray[1], &fontsize); + if (success == 1) { + g_strfreev (strarray); + return fontsize; + } + } + g_strfreev (strarray); + return fontsize; +} + +bool +FontParam::param_readSVGValue(const gchar * strvalue) +{ + double fontsize = param_readFontSize(strvalue); + Glib::ustring fontspec = param_readFontSpec(strvalue); + Inkscape::SVGOStringStream os; + os << fontspec << " @ " << fontsize; + param_setValue((Glib::ustring)os.str()); + return true; +} + +gchar * +FontParam::param_getSVGValue() const +{ + return g_strdup(value.c_str()); +} + +Gtk::Widget * +FontParam::param_newWidget() +{ + Inkscape::UI::Widget::RegisteredFontSelector * fontselectorwdg = Gtk::manage( + new Inkscape::UI::Widget::RegisteredFontSelector( param_label, + param_tooltip, + param_key, + *param_wr, + param_effect->getRepr(), + param_effect->getSPDoc() ) ); + double fontsize = param_readFontSize(param_getSVGValue()); + Glib::ustring fontspec = param_readFontSpec(param_getSVGValue()); + fontselectorwdg->setValue( fontspec, fontsize ); + fontselectorwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change font selector parameter")); + + return dynamic_cast (fontselectorwdg); +} + +void +FontParam::param_setValue(const Glib::ustring newvalue) +{ + value = newvalue; +} + +} /* namespace LivePathEffect */ + +} /* namespace Inkscape */ + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/live_effects/parameter/font.h b/src/live_effects/parameter/font.h new file mode 100644 index 000000000..e7bcc59d2 --- /dev/null +++ b/src/live_effects/parameter/font.h @@ -0,0 +1,77 @@ +#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_FONT_H +#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_FONT_H + +/* + * Inkscape::LivePathEffectParameters + * + * Authors: + * Released under GNU GPL, read the file 'COPYING' for more information + */ +#include +#include +#include "live_effects/parameter/parameter.h" + +namespace Inkscape { + +namespace LivePathEffect { + +class FontParam : public Parameter { +public: + FontParam( const Glib::ustring& label, + const Glib::ustring& tip, + const Glib::ustring& key, + Inkscape::UI::Widget::Registry* wr, + Effect* effect, + const Glib::ustring default_value = ""); + virtual ~FontParam() {} + + virtual Gtk::Widget * param_newWidget(); + virtual bool param_readSVGValue(const gchar * strvalue); + double param_readFontSize(const gchar * strvalue); + Glib::ustring param_readFontSpec(const gchar * strvalue); + virtual gchar * param_getSVGValue() const; + + void param_setValue(const Glib::ustring newvalue); + + virtual void param_set_default(); + + const Glib::ustring get_value() const { return defvalue; }; + +private: + FontParam(const FontParam&); + FontParam& operator=(const FontParam&); + Glib::ustring value; + Glib::ustring defvalue; + +}; + +/* + * This parameter does not display a widget in the LPE dialog; LPEs can use it to display on-canvas + * text that should not be settable by the user. Note that since no widget is provided, the + * parameter must be initialized differently than usual (only with a pointer to the parent effect; + * no label, no tooltip, etc.). + */ +class FontParamInternal : public FontParam { +public: + FontParamInternal(Effect* effect) : + FontParam("", "", "", NULL, effect) {} + + virtual Gtk::Widget * param_newWidget() { return NULL; } +}; + +} //namespace LivePathEffect + +} //namespace Inkscape + +#endif + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/live_effects/parameter/point.cpp b/src/live_effects/parameter/point.cpp index ca3471b29..b4f2c7758 100644 --- a/src/live_effects/parameter/point.cpp +++ b/src/live_effects/parameter/point.cpp @@ -134,7 +134,7 @@ PointParam::param_newWidget() Gtk::HBox * hbox = Gtk::manage( new Gtk::HBox() ); static_cast(hbox)->pack_start(*pointwdg, true, true); static_cast(hbox)->show_all_children(); - + param_effect->upd_params = false; return dynamic_cast (hbox); } diff --git a/src/live_effects/parameter/point.h b/src/live_effects/parameter/point.h index 4329e0bcd..06773c80e 100644 --- a/src/live_effects/parameter/point.h +++ b/src/live_effects/parameter/point.h @@ -11,7 +11,6 @@ #include #include <2geom/point.h> - #include "live_effects/parameter/parameter.h" #include "knot-holder-entity.h" diff --git a/src/live_effects/parameter/texttopath.cpp b/src/live_effects/parameter/texttopath.cpp deleted file mode 100644 index 8625e4d71..000000000 --- a/src/live_effects/parameter/texttopath.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (C) Maximilian Albert 2008 - * - * Authors: - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include "ui/widget/registered-widget.h" -#include - -#include "live_effects/parameter/texttopath.h" -#include "live_effects/effect.h" -#include "svg/svg.h" -#include "svg/stringstream.h" -#include "widgets/icon.h" -#include "inkscape.h" -#include "verbs.h" -#include "display/canvas-text.h" - -#include <2geom/sbasis-geometric.h> - -namespace Inkscape { - -namespace LivePathEffect { - -TextToPathParam::TextToPathParam( const Glib::ustring& label, const Glib::ustring& tip, - const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, - Effect* effect, const Glib::ustring default_value ) - : Parameter(label, tip, key, wr, effect), - value(default_value), - defvalue(default_value) -{ - SPDesktop *desktop = SP_ACTIVE_DESKTOP; // FIXME: we shouldn't use this! - canvas_text = (SPCanvasText *) sp_canvastext_new(desktop->getTempGroup(), desktop, Geom::Point(0,0), ""); - sp_canvastext_set_text (canvas_text, default_value.c_str()); - sp_canvastext_set_coords (canvas_text, 0, 0); -} - -void -TextToPathParam::param_set_default() -{ - param_setValue(defvalue); -} - -void -TextToPathParam::setPos(Geom::Point pos) -{ - sp_canvastext_set_coords (canvas_text, pos); -} - -void -TextToPathParam::setPosAndAnchor(const Geom::Piecewise > &pwd2, - const double t, const double length, bool /*use_curvature*/) -{ - using namespace Geom; - - Piecewise > pwd2_reparam = arc_length_parametrization(pwd2, 2 , 0.1); - double t_reparam = pwd2_reparam.cuts.back() * t; - Point pos = pwd2_reparam.valueAt(t_reparam); - Point dir = unit_vector(derivative(pwd2_reparam).valueAt(t_reparam)); - Point n = -rot90(dir); - double angle = Geom::angle_between(dir, Point(1,0)); - - sp_canvastext_set_coords(canvas_text, pos + n * length); - sp_canvastext_set_anchor_manually(canvas_text, std::sin(angle), -std::cos(angle)); -} - -void -TextToPathParam::setAnchor(double x_value, double y_value) -{ - anchor_x = x_value; - anchor_y = y_value; - sp_canvastext_set_anchor_manually (canvas_text, anchor_x, anchor_y); -} - -bool -TextToPathParam::param_readSVGValue(const gchar * strvalue) -{ - param_setValue(strvalue); - return true; -} - -gchar * -TextToPathParam::param_getSVGValue() const -{ - return g_strdup(value.c_str()); -} - -Gtk::Widget * -TextToPathParam::param_newWidget() -{ - Inkscape::UI::Widget::RegisteredText *rsu = Gtk::manage(new Inkscape::UI::Widget::RegisteredText( - param_label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc())); - - rsu->setText(value.c_str()); - rsu->setProgrammatically = false; - - rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change text parameter")); - - return dynamic_cast (rsu); -} - -void -TextToPathParam::param_setValue(const Glib::ustring newvalue) -{ - value = newvalue; - - sp_canvastext_set_text (canvas_text, newvalue.c_str()); -} - -} /* namespace LivePathEffect */ - -} /* namespace Inkscape */ - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/live_effects/parameter/texttopath.h b/src/live_effects/parameter/texttopath.h deleted file mode 100644 index 9a0ee38e2..000000000 --- a/src/live_effects/parameter/texttopath.h +++ /dev/null @@ -1,87 +0,0 @@ -#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_TEXT_TO_PATH_H -#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_TEXT_TO_PATH_H - -/* - * Inkscape::LivePathEffectParameters - * - * Authors: - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include - -#include "display/canvas-bpath.h" -#include "live_effects/parameter/parameter.h" - -struct SPCanvasText; - -namespace Inkscape { - -namespace LivePathEffect { - -class TextToPathParam : public Parameter { -public: - TextToPathParam( const Glib::ustring& label, - const Glib::ustring& tip, - const Glib::ustring& key, - Inkscape::UI::Widget::Registry* wr, - Effect* effect, - const Glib::ustring default_value = ""); - virtual ~TextToPathParam() {} - - virtual Gtk::Widget * param_newWidget(); - - virtual bool param_readSVGValue(const gchar * strvalue); - virtual gchar * param_getSVGValue() const; - - void param_setValue(const Glib::ustring newvalue); - virtual void param_set_default(); - void setPos(Geom::Point pos); - void setPosAndAnchor(const Geom::Piecewise > &pwd2, - const double t, const double length, bool use_curvature = false); - void setAnchor(double x_value, double y_value); - - const Glib::ustring get_value() const { return defvalue; }; - -private: - TextToPathParam(const TextToPathParam&); - TextToPathParam& operator=(const TextToPathParam&); - double anchor_x; - double anchor_y; - - Glib::ustring value; - Glib::ustring defvalue; - - SPCanvasText *canvas_text; -}; - -/* - * This parameter does not display a widget in the LPE dialog; LPEs can use it to display on-canvas - * text that should not be settable by the user. Note that since no widget is provided, the - * parameter must be initialized differently than usual (only with a pointer to the parent effect; - * no label, no tooltip, etc.). - */ -class TextToPathParamInternal : public TextToPathParam { -public: - TextToPathParamInternal(Effect* effect) : - TextToPathParam("", "", "", NULL, effect) {} - - virtual Gtk::Widget * param_newWidget() { return NULL; } -}; - -} //namespace LivePathEffect - -} //namespace Inkscape - -#endif - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/live_effects/parameter/togglebutton.cpp b/src/live_effects/parameter/togglebutton.cpp index 47a8b5615..5977a5114 100644 --- a/src/live_effects/parameter/togglebutton.cpp +++ b/src/live_effects/parameter/togglebutton.cpp @@ -12,6 +12,7 @@ #include "live_effects/effect.h" #include "svg/svg.h" #include "svg/stringstream.h" +#include "selection.h" #include "widgets/icon.h" #include "inkscape.h" #include "verbs.h" @@ -106,6 +107,7 @@ ToggleButtonParam::param_newWidget() }else{ gtk_box_pack_start (GTK_BOX(boxButton), labelButton, false, false, 1); } + param_effect->upd_params = false; checkwdg->add(*Gtk::manage(Glib::wrap(boxButton))); checkwdg->setActive(value); checkwdg->setProgrammatically = false; @@ -157,6 +159,12 @@ ToggleButtonParam::param_setValue(bool newvalue) void ToggleButtonParam::toggled() { + //Force redraw for update widgets + param_effect->upd_params = true; + if (SP_ACTIVE_DESKTOP) { + Inkscape::Selection *selection = SP_ACTIVE_DESKTOP->getSelection(); + selection ->emitModified(); + } _signal_toggled.emit(); } -- cgit v1.2.3 From 066d5189a44b52d9bb4f75633e6748b73bfc2a8a Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 24 Jul 2016 19:00:29 +0200 Subject: Fix a var name bug (bzr r15017.1.4) --- src/live_effects/parameter/togglebutton.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/live_effects') diff --git a/src/live_effects/parameter/togglebutton.cpp b/src/live_effects/parameter/togglebutton.cpp index b30a5a3d2..dd1717b40 100644 --- a/src/live_effects/parameter/togglebutton.cpp +++ b/src/live_effects/parameter/togglebutton.cpp @@ -110,7 +110,7 @@ ToggleButtonParam::param_newWidget() gtk_box_pack_start (GTK_BOX(box_button), label_button, false, false, 1); } - checkwdg->add(*Gtk::manage(Glib::wrap(boxButton))); + checkwdg->add(*Gtk::manage(Glib::wrap(box_button))); checkwdg->setActive(value); checkwdg->setProgrammatically = false; checkwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change togglebutton parameter")); -- cgit v1.2.3 From 10790202dbd81463005cc3ae7cdb6f2068003adb Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 25 Jul 2016 01:43:33 +0200 Subject: Add strore parameters (bzr r15017.1.5) --- src/live_effects/lpe-measure-line.cpp | 265 ++++++++++++++++++++++--------- src/live_effects/lpe-measure-line.h | 18 ++- src/live_effects/parameter/bool.cpp | 6 + src/live_effects/parameter/bool.h | 2 +- src/live_effects/parameter/font.cpp | 7 +- src/live_effects/parameter/font.h | 1 + src/live_effects/parameter/parameter.cpp | 7 + src/live_effects/parameter/parameter.h | 1 + src/live_effects/parameter/point.cpp | 4 +- src/live_effects/parameter/point.h | 2 +- src/live_effects/parameter/unit.cpp | 6 + src/live_effects/parameter/unit.h | 1 + 12 files changed, 239 insertions(+), 81 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 7b823b072..dc5d856cf 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -10,6 +10,13 @@ #include "inkscape.h" #include "uri.h" #include "uri-references.h" +#include "preferences.h" +#include "util/units.h" +#include "svg/svg-length.h" +#include "display/curve.h" +#include "sp-root.h" +#include "sp-shape.h" +#include "sp-path.h" #include "desktop.h" #include "document.h" @@ -22,99 +29,209 @@ namespace LivePathEffect { LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : Effect(lpeobject), - fontselector(_("Font Selector:"), _("Font Selector"), "fontselector", &wr, this, " ") + fontselector(_("Font Selector:"), _("Font Selector"), "fontselector", &wr, this, " "), + scale(_("Scale:"), _("Scaling factor"), "scale", &wr, this, 1.0), + precision(_("Number precision"), _("Number precision"), "precision", &wr, this, 2), + unit(_("Unit:"), _("Unit"), "unit", &wr, this), + reverse(_("To other side"), _("To other side"), "reverse", &wr, this, false), + pos(0,0), + angle(0) { registerParameter(&fontselector); + registerParameter(&scale); + registerParameter(&precision); + registerParameter(&unit); + registerParameter(&reverse); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + fontselector.param_update_default(prefs->getString("/live_effects/measure-line/fontselector")); + scale.param_update_default(prefs->getDouble("/live_effects/measure-line/scale", 1.0)); + precision.param_update_default(prefs->getInt("/live_effects/measure-line/precision", 2)); + unit.param_update_default(prefs->getString("/live_effects/measure-line/unit")); + reverse.param_update_default(prefs->getBool("/live_effects/measure-line/reverse")); rtext = NULL; + precision.param_set_range(0, 100); + precision.param_set_increments(1, 1); + precision.param_set_digits(0); + precision.param_make_integer(true); fontlister = Inkscape::FontLister::get_instance(); } LPEMeasureLine::~LPEMeasureLine() {} +void +LPEMeasureLine::doOnApply(SPLPEItem const* lpeitem) +{ + if (!SP_IS_SHAPE(lpeitem)) { + g_warning("LPE measure line can only be applied to shapes (not groups)."); + SPLPEItem * item = const_cast(lpeitem); + item->removeCurrentPathEffect(false); + } +} + void LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) { - if (SP_ACTIVE_DESKTOP) { - SPDesktop *desktop = SP_ACTIVE_DESKTOP; - Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); - Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_mlsize").c_str()); - Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); - SVGElemRef->attach(SVGElem_uri); - SPObject *elemref = NULL; - Inkscape::XML::Node *rtspan = NULL; - if (elemref = SVGElemRef->getObject()) { - rtext = elemref->getRepr(); - sp_repr_set_svg_double(rtext, "x", 0); - sp_repr_set_svg_double(rtext, "y", 0); - } else { - rtext = xml_doc->createElement("svg:text"); - rtext->setAttribute("xml:space", "preserve"); - rtext->setAttribute("id", ((Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_mlsize").c_str()); - /* Set style */ - sp_repr_set_svg_double(rtext, "x", 0); - sp_repr_set_svg_double(rtext, "y", 0); - /* Create */ - rtspan = xml_doc->createElement("svg:tspan"); - rtspan->setAttribute("sodipodi:role", "line"); + SPLPEItem * splpeitem = const_cast(lpeitem); + SPPath *sp_path = dynamic_cast(splpeitem); + if (sp_path) { + Geom::PathVector pathvector = sp_path->get_original_curve()->get_pathvector(); + if (SP_ACTIVE_DESKTOP) { + Geom::Point s = pathvector.initialPoint(); + Geom::Point e = pathvector.finalPoint(); + pos = Geom::middle_point(s,e); + Geom::Ray ray(s,e); + angle = ray.angle(); + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + doc_unit = Inkscape::Util::unit_table.getUnit(desktop->doc()->getRoot()->height.unit)->abbr; + if (reverse) { + angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); + if (angle < 0) angle += 2*M_PI; + } + Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); + if (angle_cross < 0) angle_cross += 2*M_PI; + Geom::Point newpos = pos - Point::polar(angle_cross, 10); + Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_mlsize").c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + Inkscape::XML::Node *rtspan = NULL; + if (elemref = SVGElemRef->getObject()) { + rtext = elemref->getRepr(); + sp_repr_set_svg_double(rtext, "x", newpos[Geom::X]); + sp_repr_set_svg_double(rtext, "y", newpos[Geom::Y]); + } else { + rtext = xml_doc->createElement("svg:text"); + rtext->setAttribute("xml:space", "preserve"); + rtext->setAttribute("id", ((Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_mlsize").c_str()); + /* Set style */ + sp_repr_set_svg_double(rtext, "x", newpos[Geom::X]); + sp_repr_set_svg_double(rtext, "y", newpos[Geom::Y]); + /* Create */ + rtspan = xml_doc->createElement("svg:tspan"); + rtspan->setAttribute("sodipodi:role", "line"); + } + SPCSSAttr *css = sp_repr_css_attr_new(); + Glib::ustring fontspec = fontselector.param_readFontSpec(fontselector.param_getSVGValue()); + double fontsize = fontselector.param_readFontSize(fontselector.param_getSVGValue()); + fontlister->fill_css( css, fontspec ); + std::stringstream font_size; + font_size.imbue(std::locale::classic()); + font_size << fontsize << "pt"; + sp_repr_css_set_property (css, "font-size", font_size.str().c_str()); + sp_repr_css_set_property (css, "font-style", "normal"); + sp_repr_css_set_property (css, "font-weight", "normal"); + sp_repr_css_set_property (css, "line-height", "125%"); + sp_repr_css_set_property (css, "letter-spacing", "0"); + sp_repr_css_set_property (css, "word-spacing", "0"); + sp_repr_css_set_property (css, "text-align", "center"); + sp_repr_css_set_property (css, "text-anchor", "middle"); + sp_repr_css_set_property (css, "fill", "#000000"); + sp_repr_css_set_property (css, "fill-opacity", "1"); + sp_repr_css_set_property (css, "stroke", "none"); + Glib::ustring css_str; + sp_repr_css_write_string(css,css_str); + if (!rtspan) { + rtspan = rtext->firstChild(); + } + rtspan->setAttribute("style", css_str.c_str()); + sp_repr_css_attr_unref (css); + if (!elemref) { + rtext->addChild(rtspan, NULL); + Inkscape::GC::release(rtspan); + } + /* Create TEXT */ + length = Inkscape::Util::Quantity::convert(length, doc_unit.c_str(), unit.get_abbreviation()); + std::stringstream length_str; + length_str.imbue(std::locale::classic()); + length_str << "%." << precision << "f %s"; + gchar *lengthchar = g_strdup_printf(length_str.str().c_str(), length, unit.get_abbreviation()); + Inkscape::XML::Node *rstring = NULL; + if (!elemref) { + rstring = xml_doc->createTextNode(lengthchar); + rtspan->addChild(rstring, NULL); + Inkscape::GC::release(rstring); + } else { + rstring = rtspan->firstChild(); + rstring->setContent(lengthchar); + } + SPObject * text_obj = NULL; + if (!elemref) { + text_obj = SP_OBJECT(desktop->currentLayer()->appendChildRepr(rtext)); + Inkscape::GC::release(rtext); + } else { + text_obj = desktop->currentLayer()->get_child_by_repr(rtext); + } + Geom::Affine affine = Geom::Affine(Geom::Translate(newpos).inverse()); + affine *= Geom::Rotate(angle); + affine *= Geom::Translate(newpos); + SP_ITEM(text_obj)->transform = affine; + text_obj->updateRepr(); } - SPCSSAttr *css = sp_repr_css_attr_new(); - Glib::ustring fontspec = fontselector.param_readFontSpec(fontselector.param_getSVGValue()); - double fontsize = fontselector.param_readFontSize(fontselector.param_getSVGValue()); - fontlister->fill_css( css, fontspec ); - std::stringstream font_size; - font_size.imbue(std::locale::classic()); - font_size << fontsize << "pt"; - sp_repr_css_set_property (css, "font-size", font_size.str().c_str()); - sp_repr_css_set_property (css, "font-style", "normal"); - sp_repr_css_set_property (css, "font-weight", "normal"); - sp_repr_css_set_property (css, "line-height", "125%"); - sp_repr_css_set_property (css, "letter-spacing", "0"); - sp_repr_css_set_property (css, "word-spacing", "0"); - sp_repr_css_set_property (css, "text-align", "center"); - sp_repr_css_set_property (css, "text-anchor", "middle"); - sp_repr_css_set_property (css, "fill", "#000000"); - sp_repr_css_set_property (css, "fill-opacity", "1"); - sp_repr_css_set_property (css, "stroke", "none"); - Glib::ustring css_str; - sp_repr_css_write_string(css,css_str); - if (!rtspan) { - rtspan = rtext->firstChild(); - } - rtspan->setAttribute("style", css_str.c_str()); - sp_repr_css_attr_unref (css); - if (!elemref) { - rtext->addChild(rtspan, NULL); - Inkscape::GC::release(rtspan); - } - /* Create TEXT */ - std::stringstream lenghtstr; - lenghtstr.imbue(std::locale::classic()); - lenghtstr << lenght; - Inkscape::XML::Node *rstring = NULL; - if (!elemref) { - rstring = xml_doc->createTextNode(lenghtstr.str().c_str()); - rtspan->addChild(rstring, NULL); - Inkscape::GC::release(rstring); - } else { - rstring = rtspan->firstChild(); - rstring->setContent(lenghtstr.str().c_str()); - } - SPObject * text_obj = NULL; - if (!elemref) { - text_obj = SP_OBJECT(desktop->currentLayer()->appendChildRepr(rtext)); - Inkscape::GC::release(rtext); - } else { - text_obj = desktop->currentLayer()->get_child_by_repr(rtext); + } +} + +Gtk::Widget *LPEMeasureLine::newWidget() +{ + // use manage here, because after deletion of Effect object, others might + // still be pointing to this widget. + Gtk::VBox *vbox = Gtk::manage(new Gtk::VBox(Effect::newWidget())); + + vbox->set_border_width(5); + vbox->set_homogeneous(false); + vbox->set_spacing(6); + + std::vector::iterator it = param_vector.begin(); + Gtk::HBox * button1 = Gtk::manage(new Gtk::HBox(true,0)); + while (it != param_vector.end()) { + if ((*it)->widget_is_visible) { + Parameter *param = *it; + Gtk::Widget *widg = dynamic_cast(param->param_newWidget()); + Glib::ustring *tip = param->param_getTooltip(); + if (widg) { + vbox->pack_start(*widg, true, true, 2); + if (tip) { + widg->set_tooltip_text(*tip); + } else { + widg->set_tooltip_text(""); + widg->set_has_tooltip(false); + } + } } - text_obj->updateRepr(); + + ++it; } + Gtk::Button *save_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Save as default")))); + save_default->signal_clicked().connect(sigc::mem_fun(*this, &LPEMeasureLine::saveDefault)); + button1->pack_start(*save_default, true, true, 2); + vbox->pack_start(*button1, true, true, 2); + return dynamic_cast(vbox); } Geom::PathVector LPEMeasureLine::doEffect_path(Geom::PathVector const &path_in) { - lenght = Geom::distance(path_in.initialPoint(), path_in.finalPoint()); - return path_in; + + length = Geom::distance(path_in.initialPoint(), path_in.finalPoint()) * scale; + Geom::Path path; + Geom::Point s = path_in.initialPoint(); + Geom::Point e = path_in.finalPoint(); + path.start( s ); + path.appendNew( e ); + Geom::PathVector output; + output.push_back(path); + return output; +} + +void +LPEMeasureLine::saveDefault() +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setString("/live_effects/measure-line/fontselector", (Glib::ustring)fontselector.param_getSVGValue()); + prefs->setDouble("/live_effects/measure-line/scale", scale); + prefs->setInt("/live_effects/measure-line/precision", precision); + prefs->setString("/live_effects/measure-line/unit", (Glib::ustring)unit.get_abbreviation()); + prefs->setInt("/live_effects/measure-line/reverse", reverse); } }; //namespace LivePathEffect diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index 7e576ffe6..3b05cb18c 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -11,7 +11,13 @@ */ #include "live_effects/parameter/font.h" #include "live_effects/effect.h" +#include "live_effects/parameter/text.h" +#include "live_effects/parameter/unit.h" +#include "live_effects/parameter/bool.h" #include +#include <2geom/angle.h> +#include <2geom/ray.h> +#include <2geom/point.h> #include "xml/node.h" @@ -23,12 +29,22 @@ public: LPEMeasureLine(LivePathEffectObject *lpeobject); virtual ~LPEMeasureLine(); virtual void doBeforeEffect (SPLPEItem const* lpeitem); + virtual void doOnApply(SPLPEItem const* lpeitem); virtual Geom::PathVector doEffect_path(Geom::PathVector const &path_in); + void saveDefault(); + virtual Gtk::Widget *newWidget(); private: - double lenght; + double length; FontParam fontselector; Inkscape::FontLister *fontlister; Inkscape::XML::Node *rtext; + Geom::Point pos; + Geom::Coord angle; + ScalarParam scale; + ScalarParam precision; + UnitParam unit; + BoolParam reverse; + Glib::ustring doc_unit; LPEMeasureLine(const LPEMeasureLine &); LPEMeasureLine &operator=(const LPEMeasureLine &); diff --git a/src/live_effects/parameter/bool.cpp b/src/live_effects/parameter/bool.cpp index 9ecadbdeb..af99ef362 100644 --- a/src/live_effects/parameter/bool.cpp +++ b/src/live_effects/parameter/bool.cpp @@ -36,6 +36,12 @@ BoolParam::param_set_default() param_setValue(defvalue); } +void +BoolParam::param_update_default(bool const default_value) +{ + defvalue = default_value; +} + bool BoolParam::param_readSVGValue(const gchar * strvalue) { diff --git a/src/live_effects/parameter/bool.h b/src/live_effects/parameter/bool.h index 403dd0b87..7ad8a9368 100644 --- a/src/live_effects/parameter/bool.h +++ b/src/live_effects/parameter/bool.h @@ -36,7 +36,7 @@ public: void param_setValue(bool newvalue); virtual void param_set_default(); - + void param_update_default(bool const default_value); bool get_value() const { return value; }; inline operator bool() const { return value; }; diff --git a/src/live_effects/parameter/font.cpp b/src/live_effects/parameter/font.cpp index 174b66152..8f89ee5c4 100644 --- a/src/live_effects/parameter/font.cpp +++ b/src/live_effects/parameter/font.cpp @@ -33,7 +33,10 @@ FontParam::param_set_default() { param_setValue(defvalue); } - +void +FontParam::param_update_default(const Glib::ustring default_value){ + defvalue = default_value; +} Glib::ustring FontParam::param_readFontSpec(const gchar * strvalue) @@ -100,7 +103,7 @@ FontParam::param_newWidget() Glib::ustring fontspec = param_readFontSpec(param_getSVGValue()); fontselectorwdg->setValue( fontspec, fontsize ); fontselectorwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change font selector parameter")); - + param_effect->upd_params = false; return dynamic_cast (fontselectorwdg); } diff --git a/src/live_effects/parameter/font.h b/src/live_effects/parameter/font.h index e7bcc59d2..3909ea424 100644 --- a/src/live_effects/parameter/font.h +++ b/src/live_effects/parameter/font.h @@ -28,6 +28,7 @@ public: virtual Gtk::Widget * param_newWidget(); virtual bool param_readSVGValue(const gchar * strvalue); double param_readFontSize(const gchar * strvalue); + void param_update_default(const Glib::ustring defvalue); Glib::ustring param_readFontSpec(const gchar * strvalue); virtual gchar * param_getSVGValue() const; diff --git a/src/live_effects/parameter/parameter.cpp b/src/live_effects/parameter/parameter.cpp index d4e213948..ae55c84e9 100644 --- a/src/live_effects/parameter/parameter.cpp +++ b/src/live_effects/parameter/parameter.cpp @@ -101,6 +101,12 @@ ScalarParam::param_set_default() param_set_value(defvalue); } +void +ScalarParam::param_update_default(gdouble default_value) +{ + defvalue = default_value; +} + void ScalarParam::param_set_value(gdouble val) { @@ -169,6 +175,7 @@ ScalarParam::param_newWidget() if(!overwrite_widget){ rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change scalar parameter")); } + param_effect->upd_params = false; return dynamic_cast (rsu); } else { return NULL; diff --git a/src/live_effects/parameter/parameter.h b/src/live_effects/parameter/parameter.h index 0ef28650a..8556b0d9a 100644 --- a/src/live_effects/parameter/parameter.h +++ b/src/live_effects/parameter/parameter.h @@ -110,6 +110,7 @@ public: virtual gchar * param_getSVGValue() const; virtual void param_set_default(); + void param_update_default(gdouble default_value); void param_set_value(gdouble val); void param_make_integer(bool yes = true); void param_set_range(gdouble min, gdouble max); diff --git a/src/live_effects/parameter/point.cpp b/src/live_effects/parameter/point.cpp index b4f2c7758..90a5b252b 100644 --- a/src/live_effects/parameter/point.cpp +++ b/src/live_effects/parameter/point.cpp @@ -62,9 +62,9 @@ PointParam::param_get_default() const{ } void -PointParam::param_update_default(Geom::Point newpoint) +PointParam::param_update_default(const Geom::Point default_point) { - defvalue = newpoint; + defvalue = default_point; } void diff --git a/src/live_effects/parameter/point.h b/src/live_effects/parameter/point.h index 06773c80e..d41e8a710 100644 --- a/src/live_effects/parameter/point.h +++ b/src/live_effects/parameter/point.h @@ -42,7 +42,7 @@ public: void param_set_default(); Geom::Point param_get_default() const; void param_set_liveupdate(bool live_update); - void param_update_default(Geom::Point newpoint); + void param_update_default(const Geom::Point default_point); virtual void param_transform_multiply(Geom::Affine const& /*postmul*/, bool /*set*/); void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color); diff --git a/src/live_effects/parameter/unit.cpp b/src/live_effects/parameter/unit.cpp index 0ee553e2c..b6ea99bfe 100644 --- a/src/live_effects/parameter/unit.cpp +++ b/src/live_effects/parameter/unit.cpp @@ -54,6 +54,12 @@ UnitParam::param_set_default() param_set_value(*defunit); } +void +UnitParam::param_update_default(const Glib::ustring default_unit) +{ + defunit = unit_table.getUnit(default_unit); +} + void UnitParam::param_set_value(Inkscape::Util::Unit const &val) { diff --git a/src/live_effects/parameter/unit.h b/src/live_effects/parameter/unit.h index 59a483018..ae58cf956 100644 --- a/src/live_effects/parameter/unit.h +++ b/src/live_effects/parameter/unit.h @@ -33,6 +33,7 @@ public: virtual gchar * param_getSVGValue() const; virtual void param_set_default(); void param_set_value(Inkscape::Util::Unit const &val); + void param_update_default(const Glib::ustring default_unit); const gchar *get_abbreviation() const; virtual Gtk::Widget * param_newWidget(); -- cgit v1.2.3 From d7bdf3ed2d198c0027babed217dfec32f5f4f389 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 26 Jul 2016 00:10:01 +0200 Subject: Add gap,offset,insensitive transforms, and delete on lpe remove (bzr r15017.1.6) --- src/live_effects/lpe-measure-line.cpp | 101 +++++++++++++++++++++++++++++++--- src/live_effects/lpe-measure-line.h | 8 +++ 2 files changed, 102 insertions(+), 7 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index dc5d856cf..3d5cd8591 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -13,8 +13,12 @@ #include "preferences.h" #include "util/units.h" #include "svg/svg-length.h" +#include "svg/svg-color.h" #include "display/curve.h" +#include <2geom/affine.h> +#include "style.h" #include "sp-root.h" +#include "sp-item.h" #include "sp-shape.h" #include "sp-path.h" #include "desktop.h" @@ -32,27 +36,57 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : fontselector(_("Font Selector:"), _("Font Selector"), "fontselector", &wr, this, " "), scale(_("Scale:"), _("Scaling factor"), "scale", &wr, this, 1.0), precision(_("Number precision"), _("Number precision"), "precision", &wr, this, 2), + offset_right_left(_("Offset right left"), _("Offset right left"), "offset_right_left", &wr, this, 0), + offset_top_bottom(_("Offset top bottom"), _("Offset top bottom"), "offset_top_bottom", &wr, this, 10), + gap_start(_("Gap to line from origin"), _("Gap to line from origin, without affecting measure"), "gap_start", &wr, this, 0), + gap_end(_("Gap to line from end"), _("Gap to line from end, without affecting measure"), "gap_end", &wr, this, 0), unit(_("Unit:"), _("Unit"), "unit", &wr, this), reverse(_("To other side"), _("To other side"), "reverse", &wr, this, false), + color_as_line(_("Measure color as line"), _("Measure color as line"), "color_as_line", &wr, this, false), + scale_insensitive(_("Scale insensitive"), _("Scale insensitive to transforms in element, parents..."), "scale_insensitive", &wr, this, true), pos(0,0), angle(0) { registerParameter(&fontselector); registerParameter(&scale); registerParameter(&precision); + registerParameter(&offset_right_left); + registerParameter(&offset_top_bottom); + registerParameter(&gap_start); + registerParameter(&gap_end); registerParameter(&unit); registerParameter(&reverse); + registerParameter(&color_as_line); + registerParameter(&scale_insensitive); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); fontselector.param_update_default(prefs->getString("/live_effects/measure-line/fontselector")); scale.param_update_default(prefs->getDouble("/live_effects/measure-line/scale", 1.0)); precision.param_update_default(prefs->getInt("/live_effects/measure-line/precision", 2)); + offset_right_left.param_update_default(prefs->getDouble("/live_effects/measure-line/offset_right_left", 0.0)); + offset_top_bottom.param_update_default(prefs->getDouble("/live_effects/measure-line/offset_top_bottom", 10.0)); + gap_start.param_update_default(prefs->getDouble("/live_effects/measure-line/gap_start", 0.0)); + gap_end.param_update_default(prefs->getDouble("/live_effects/measure-line/gap_end", 0.0)); unit.param_update_default(prefs->getString("/live_effects/measure-line/unit")); reverse.param_update_default(prefs->getBool("/live_effects/measure-line/reverse")); + color_as_line.param_update_default(prefs->getBool("/live_effects/measure-line/color_as_line")); + scale_insensitive.param_update_default(prefs->getBool("/live_effects/measure-line/scale_insensitive")); rtext = NULL; precision.param_set_range(0, 100); precision.param_set_increments(1, 1); precision.param_set_digits(0); precision.param_make_integer(true); + offset_right_left.param_set_range(-999999.0, 999999.0); + offset_right_left.param_set_increments(1, 1); + offset_right_left.param_set_digits(2); + offset_top_bottom.param_set_range(-999999.0, 999999.0); + offset_top_bottom.param_set_increments(1, 1); + offset_top_bottom.param_set_digits(2); + gap_start.param_set_range(-999999.0, 999999.0); + gap_start.param_set_increments(1, 1); + gap_start.param_set_digits(2); + gap_end.param_set_range(-999999.0, 999999.0); + gap_end.param_set_increments(1, 1); + gap_end.param_set_digits(2); fontlister = Inkscape::FontLister::get_instance(); } @@ -75,21 +109,22 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) SPPath *sp_path = dynamic_cast(splpeitem); if (sp_path) { Geom::PathVector pathvector = sp_path->get_original_curve()->get_pathvector(); - if (SP_ACTIVE_DESKTOP) { + if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { Geom::Point s = pathvector.initialPoint(); Geom::Point e = pathvector.finalPoint(); + length = Geom::distance(path_in.initialPoint(), path_in.finalPoint()) * scale; pos = Geom::middle_point(s,e); Geom::Ray ray(s,e); angle = ray.angle(); - SPDesktop *desktop = SP_ACTIVE_DESKTOP; doc_unit = Inkscape::Util::unit_table.getUnit(desktop->doc()->getRoot()->height.unit)->abbr; if (reverse) { angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); if (angle < 0) angle += 2*M_PI; } + Geom::Point newpos = pos - Point::polar(angle, offset_right_left); Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); if (angle_cross < 0) angle_cross += 2*M_PI; - Geom::Point newpos = pos - Point::polar(angle_cross, 10); + newpos = newpos - Point::polar(angle_cross, offset_top_bottom); Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_mlsize").c_str()); Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); @@ -103,6 +138,7 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } else { rtext = xml_doc->createElement("svg:text"); rtext->setAttribute("xml:space", "preserve"); + rtext->setAttribute("sodipodi:insensitive", "true"); rtext->setAttribute("id", ((Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_mlsize").c_str()); /* Set style */ sp_repr_set_svg_double(rtext, "x", newpos[Geom::X]); @@ -126,7 +162,30 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) sp_repr_css_set_property (css, "word-spacing", "0"); sp_repr_css_set_property (css, "text-align", "center"); sp_repr_css_set_property (css, "text-anchor", "middle"); - sp_repr_css_set_property (css, "fill", "#000000"); + if (color_as_line) { + if (lpeitem->style) { + if (lpeitem->style->stroke.isPaintserver()) { + SPPaintServer * server = lpeitem->style->getStrokePaintServer(); + if (server) { + Glib::ustring str; + str += "url(#"; + str += server->getId(); + str += ")"; + sp_repr_css_set_property (css, "fill", str.c_str()); + } + } else if (lpeitem->style->stroke.isColor()) { + gchar c[64]; + sp_svg_write_color (c, sizeof(c), lpeitem->style->stroke.value.color.toRGBA32(SP_SCALE24_TO_FLOAT(lpeitem->style->stroke_opacity.value))); + sp_repr_css_set_property (css, "fill", c); + } else { + sp_repr_css_set_property (css, "fill", "#000000"); + } + } else { + sp_repr_css_unset_property (css, "#000000"); + } + } else { + sp_repr_css_set_property (css, "fill", "#000000"); + } sp_repr_css_set_property (css, "fill-opacity", "1"); sp_repr_css_set_property (css, "stroke", "none"); Glib::ustring css_str; @@ -141,6 +200,10 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) Inkscape::GC::release(rtspan); } /* Create TEXT */ + if (!scale_insensitive) { + Geom::Affine affinetransform = i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(desktop->doc()->getRoot())); + length *= (affinetransform.expansionX() + affinetransform.expansionY()) / 2.0; + } length = Inkscape::Util::Quantity::convert(length, doc_unit.c_str(), unit.get_abbreviation()); std::stringstream length_str; length_str.imbue(std::locale::classic()); @@ -165,12 +228,24 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) Geom::Affine affine = Geom::Affine(Geom::Translate(newpos).inverse()); affine *= Geom::Rotate(angle); affine *= Geom::Translate(newpos); - SP_ITEM(text_obj)->transform = affine; + SP_ITEM(text_obj)->transform = affine * i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(desktop->doc()->getRoot())); text_obj->updateRepr(); } } } +void LPEMeasureLine::doOnRemove (SPLPEItem const* /*lpeitem*/) +{ + if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { + rtext->setAttribute("sodipodi:insensitive", NULL); + SPObject * text_obj = desktop->currentLayer()->get_child_by_repr(rtext); + if (text_obj) { + text_obj->updateRepr(); + text_obj->deleteObject(); + } + } +} + Gtk::Widget *LPEMeasureLine::newWidget() { // use manage here, because after deletion of Effect object, others might @@ -211,11 +286,17 @@ Gtk::Widget *LPEMeasureLine::newWidget() Geom::PathVector LPEMeasureLine::doEffect_path(Geom::PathVector const &path_in) { - - length = Geom::distance(path_in.initialPoint(), path_in.finalPoint()) * scale; Geom::Path path; Geom::Point s = path_in.initialPoint(); Geom::Point e = path_in.finalPoint(); + if (reverse) { + angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); + if (angle < 0) angle += 2*M_PI; + } + s = s - Point::polar(angle, gap_start); + angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); + if (angle < 0) angle += 2*M_PI; + e = e - Point::polar(angle, gap_end); path.start( s ); path.appendNew( e ); Geom::PathVector output; @@ -230,8 +311,14 @@ LPEMeasureLine::saveDefault() prefs->setString("/live_effects/measure-line/fontselector", (Glib::ustring)fontselector.param_getSVGValue()); prefs->setDouble("/live_effects/measure-line/scale", scale); prefs->setInt("/live_effects/measure-line/precision", precision); + prefs->setDouble("/live_effects/measure-line/offset_right_left", offset_right_left); + prefs->setDouble("/live_effects/measure-line/offset_top_bottom", offset_top_bottom); + prefs->setDouble("/live_effects/measure-line/gap_start", gap_start); + prefs->setDouble("/live_effects/measure-line/gap_end", gap_end); prefs->setString("/live_effects/measure-line/unit", (Glib::ustring)unit.get_abbreviation()); prefs->setInt("/live_effects/measure-line/reverse", reverse); + prefs->setInt("/live_effects/measure-line/color_as_line", color_as_line); + prefs->setInt("/live_effects/measure-line/scale_insensitive", scale_insensitive); } }; //namespace LivePathEffect diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index 3b05cb18c..ba24aa404 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -30,6 +30,7 @@ public: virtual ~LPEMeasureLine(); virtual void doBeforeEffect (SPLPEItem const* lpeitem); virtual void doOnApply(SPLPEItem const* lpeitem); + virtual void doOnRemove (SPLPEItem const* /*lpeitem*/); virtual Geom::PathVector doEffect_path(Geom::PathVector const &path_in); void saveDefault(); virtual Gtk::Widget *newWidget(); @@ -42,9 +43,16 @@ private: Geom::Coord angle; ScalarParam scale; ScalarParam precision; + ScalarParam offset_right_left; + ScalarParam offset_top_bottom; + ScalarParam gap_start; + ScalarParam gap_end; UnitParam unit; BoolParam reverse; + BoolParam color_as_line; + BoolParam scale_insensitive; Glib::ustring doc_unit; +/* Geom::Affine affine_over;*/ LPEMeasureLine(const LPEMeasureLine &); LPEMeasureLine &operator=(const LPEMeasureLine &); -- cgit v1.2.3 From bc46160cc69e4597d94ae6dd0c70428341a4d4f2 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 28 Jul 2016 00:55:05 +0200 Subject: Add optional linked path (bzr r15017.1.8) --- src/live_effects/lpe-measure-line.cpp | 58 ++++++++++++++++++++++++++++++----- src/live_effects/lpe-measure-line.h | 8 ++++- 2 files changed, 57 insertions(+), 9 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 3d5cd8591..638d60464 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -14,6 +14,7 @@ #include "util/units.h" #include "svg/svg-length.h" #include "svg/svg-color.h" +#include "svg/svg.h" #include "display/curve.h" #include <2geom/affine.h> #include "style.h" @@ -34,10 +35,13 @@ namespace LivePathEffect { LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : Effect(lpeobject), fontselector(_("Font Selector:"), _("Font Selector"), "fontselector", &wr, this, " "), + origin(_("Optional Origin:"), _("Optional origin"), "origin", &wr, this), + curve_linked(_("Curve on optional origin:"), _("Curve on optional origin, set 0 to start/end"), "curve_linked", &wr, this, 1), + line_offset(_("Optional origin offset"), _("Optional origin offset"), "line_offset", &wr, this, 5), scale(_("Scale:"), _("Scaling factor"), "scale", &wr, this, 1.0), precision(_("Number precision"), _("Number precision"), "precision", &wr, this, 2), offset_right_left(_("Offset right left"), _("Offset right left"), "offset_right_left", &wr, this, 0), - offset_top_bottom(_("Offset top bottom"), _("Offset top bottom"), "offset_top_bottom", &wr, this, 10), + offset_top_bottom(_("Offset top bottom"), _("Offset top bottom"), "offset_top_bottom", &wr, this, 5), gap_start(_("Gap to line from origin"), _("Gap to line from origin, without affecting measure"), "gap_start", &wr, this, 0), gap_end(_("Gap to line from end"), _("Gap to line from end, without affecting measure"), "gap_end", &wr, this, 0), unit(_("Unit:"), _("Unit"), "unit", &wr, this), @@ -48,6 +52,9 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : angle(0) { registerParameter(&fontselector); + registerParameter(&origin); + registerParameter(&curve_linked); + registerParameter(&line_offset); registerParameter(&scale); registerParameter(&precision); registerParameter(&offset_right_left); @@ -63,9 +70,8 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : scale.param_update_default(prefs->getDouble("/live_effects/measure-line/scale", 1.0)); precision.param_update_default(prefs->getInt("/live_effects/measure-line/precision", 2)); offset_right_left.param_update_default(prefs->getDouble("/live_effects/measure-line/offset_right_left", 0.0)); - offset_top_bottom.param_update_default(prefs->getDouble("/live_effects/measure-line/offset_top_bottom", 10.0)); - gap_start.param_update_default(prefs->getDouble("/live_effects/measure-line/gap_start", 0.0)); - gap_end.param_update_default(prefs->getDouble("/live_effects/measure-line/gap_end", 0.0)); + offset_top_bottom.param_update_default(prefs->getDouble("/live_effects/measure-line/offset_top_bottom", 5.0)); + line_offset.param_update_default(prefs->getDouble("/live_effects/measure-line/line_offset", 5.0)); unit.param_update_default(prefs->getString("/live_effects/measure-line/unit")); reverse.param_update_default(prefs->getBool("/live_effects/measure-line/reverse")); color_as_line.param_update_default(prefs->getBool("/live_effects/measure-line/color_as_line")); @@ -75,12 +81,20 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : precision.param_set_increments(1, 1); precision.param_set_digits(0); precision.param_make_integer(true); + curve_linked.param_set_range(1, 999); + curve_linked.param_set_increments(1, 1); + curve_linked.param_set_digits(0); + curve_linked.param_make_integer(true); + precision.param_make_integer(true); offset_right_left.param_set_range(-999999.0, 999999.0); offset_right_left.param_set_increments(1, 1); offset_right_left.param_set_digits(2); offset_top_bottom.param_set_range(-999999.0, 999999.0); offset_top_bottom.param_set_increments(1, 1); offset_top_bottom.param_set_digits(2); + line_offset.param_set_range(-999999.0, 999999.0); + line_offset.param_set_increments(1, 1); + line_offset.param_set_digits(2); gap_start.param_set_range(-999999.0, 999999.0); gap_start.param_set_increments(1, 1); gap_start.param_set_digits(2); @@ -110,9 +124,39 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) if (sp_path) { Geom::PathVector pathvector = sp_path->get_original_curve()->get_pathvector(); if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { + Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); Geom::Point s = pathvector.initialPoint(); Geom::Point e = pathvector.finalPoint(); - length = Geom::distance(path_in.initialPoint(), path_in.finalPoint()) * scale; + if (origin.linksToPath() && origin.getObject() && !origin.get_pathvector().empty()) { + pathvector = origin.get_pathvector(); + size_t ncurves = pathvector.curveCount(); + curve_linked.param_set_range(1, ncurves); + if(previous_ncurves != ncurves) { + this->upd_params = true; + previous_ncurves = ncurves; + } + s = pathvector.pointAt(curve_linked -1); + e = pathvector.pointAt(curve_linked); + Geom::Ray ray(s,e); + angle = ray.angle(); + if (reverse) { + angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); + if (angle < 0) angle += 2*M_PI; + } + Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); + if (angle_cross < 0) angle_cross += 2*M_PI; + s = s - Point::polar(angle_cross, line_offset); + e = e - Point::polar(angle_cross, line_offset); + Geom::Path path; + path.start( s ); + path.appendNew( e ); + Geom::PathVector line_upd; + line_upd.push_back(path); + Inkscape::XML::Node *line = SP_OBJECT(sp_path)->getRepr(); + gchar *str = sp_svg_write_path(line_upd); + line->setAttribute("inkscape:original-d", str); + } + length = Geom::distance(s, e) * scale; pos = Geom::middle_point(s,e); Geom::Ray ray(s,e); angle = ray.angle(); @@ -125,7 +169,6 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); if (angle_cross < 0) angle_cross += 2*M_PI; newpos = newpos - Point::polar(angle_cross, offset_top_bottom); - Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_mlsize").c_str()); Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); SVGElemRef->attach(SVGElem_uri); @@ -313,8 +356,7 @@ LPEMeasureLine::saveDefault() prefs->setInt("/live_effects/measure-line/precision", precision); prefs->setDouble("/live_effects/measure-line/offset_right_left", offset_right_left); prefs->setDouble("/live_effects/measure-line/offset_top_bottom", offset_top_bottom); - prefs->setDouble("/live_effects/measure-line/gap_start", gap_start); - prefs->setDouble("/live_effects/measure-line/gap_end", gap_end); + prefs->setDouble("/live_effects/measure-line/line_offset", line_offset); prefs->setString("/live_effects/measure-line/unit", (Glib::ustring)unit.get_abbreviation()); prefs->setInt("/live_effects/measure-line/reverse", reverse); prefs->setInt("/live_effects/measure-line/color_as_line", color_as_line); diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index ba24aa404..b03a44705 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -9,11 +9,13 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ -#include "live_effects/parameter/font.h" + #include "live_effects/effect.h" +#include "live_effects/parameter/font.h" #include "live_effects/parameter/text.h" #include "live_effects/parameter/unit.h" #include "live_effects/parameter/bool.h" +#include "live_effects/parameter/originalpath.h" #include #include <2geom/angle.h> #include <2geom/ray.h> @@ -41,12 +43,16 @@ private: Inkscape::XML::Node *rtext; Geom::Point pos; Geom::Coord angle; + OriginalPathParam origin; + ScalarParam curve_linked; + ScalarParam line_offset; ScalarParam scale; ScalarParam precision; ScalarParam offset_right_left; ScalarParam offset_top_bottom; ScalarParam gap_start; ScalarParam gap_end; + size_t previous_ncurves; UnitParam unit; BoolParam reverse; BoolParam color_as_line; -- cgit v1.2.3 From 5c04358b2fd79db36b8064ad5e7a9fd8bbe314bb Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 28 Jul 2016 12:30:52 +0200 Subject: Finish linked path and add local number format (bzr r15017.1.9) --- src/live_effects/lpe-measure-line.cpp | 96 ++++++++++++++++++++++------------- src/live_effects/lpe-measure-line.h | 4 +- 2 files changed, 64 insertions(+), 36 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 638d60464..31b1db7c2 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -24,6 +24,7 @@ #include "sp-path.h" #include "desktop.h" #include "document.h" +#include // TODO due to internal breakage in glibmm headers, this must be last: #include @@ -34,27 +35,28 @@ namespace LivePathEffect { LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : Effect(lpeobject), - fontselector(_("Font Selector:"), _("Font Selector"), "fontselector", &wr, this, " "), - origin(_("Optional Origin:"), _("Optional origin"), "origin", &wr, this), - curve_linked(_("Curve on optional origin:"), _("Curve on optional origin, set 0 to start/end"), "curve_linked", &wr, this, 1), - line_offset(_("Optional origin offset"), _("Optional origin offset"), "line_offset", &wr, this, 5), - scale(_("Scale:"), _("Scaling factor"), "scale", &wr, this, 1.0), - precision(_("Number precision"), _("Number precision"), "precision", &wr, this, 2), - offset_right_left(_("Offset right left"), _("Offset right left"), "offset_right_left", &wr, this, 0), - offset_top_bottom(_("Offset top bottom"), _("Offset top bottom"), "offset_top_bottom", &wr, this, 5), + fontselector(_("Font Selector*"), _("Font Selector"), "fontselector", &wr, this, " "), + origin(_("Optional Origin"), _("Optional origin"), "origin", &wr, this), + curve_linked(_("Curve on optional origin*"), _("Curve on optional origin, set 0 to start/end"), "curve_linked", &wr, this, 1), + origin_offset(_("Optional origin offset*"), _("Optional origin offset"), "origin_offset", &wr, this, 5), + scale(_("Scale*"), _("Scaling factor"), "scale", &wr, this, 1.0), + precision(_("Number precision*"), _("Number precision"), "precision", &wr, this, 2), + offset_right_left(_("Offset right left*"), _("Offset right left"), "offset_right_left", &wr, this, 0), + offset_top_bottom(_("Offset top bottom*"), _("Offset top bottom"), "offset_top_bottom", &wr, this, 5), gap_start(_("Gap to line from origin"), _("Gap to line from origin, without affecting measure"), "gap_start", &wr, this, 0), gap_end(_("Gap to line from end"), _("Gap to line from end, without affecting measure"), "gap_end", &wr, this, 0), - unit(_("Unit:"), _("Unit"), "unit", &wr, this), - reverse(_("To other side"), _("To other side"), "reverse", &wr, this, false), - color_as_line(_("Measure color as line"), _("Measure color as line"), "color_as_line", &wr, this, false), - scale_insensitive(_("Scale insensitive"), _("Scale insensitive to transforms in element, parents..."), "scale_insensitive", &wr, this, true), + unit(_("Unit*"), _("Unit"), "unit", &wr, this), + reverse(_("To other side*"), _("To other side"), "reverse", &wr, this, false), + color_as_line(_("Measure color as line*"), _("Measure color as line"), "color_as_line", &wr, this, false), + scale_insensitive(_("Scale insensitive*"), _("Scale insensitive to transforms in element, parents..."), "scale_insensitive", &wr, this, true), + local_locale(_("Local Number Format*"), _("Local number format"), "local_locale", &wr, this, true), pos(0,0), angle(0) { registerParameter(&fontselector); registerParameter(&origin); registerParameter(&curve_linked); - registerParameter(&line_offset); + registerParameter(&origin_offset); registerParameter(&scale); registerParameter(&precision); registerParameter(&offset_right_left); @@ -65,17 +67,19 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : registerParameter(&reverse); registerParameter(&color_as_line); registerParameter(&scale_insensitive); + registerParameter(&local_locale); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); fontselector.param_update_default(prefs->getString("/live_effects/measure-line/fontselector")); scale.param_update_default(prefs->getDouble("/live_effects/measure-line/scale", 1.0)); precision.param_update_default(prefs->getInt("/live_effects/measure-line/precision", 2)); offset_right_left.param_update_default(prefs->getDouble("/live_effects/measure-line/offset_right_left", 0.0)); offset_top_bottom.param_update_default(prefs->getDouble("/live_effects/measure-line/offset_top_bottom", 5.0)); - line_offset.param_update_default(prefs->getDouble("/live_effects/measure-line/line_offset", 5.0)); + origin_offset.param_update_default(prefs->getDouble("/live_effects/measure-line/origin_offset", 5.0)); unit.param_update_default(prefs->getString("/live_effects/measure-line/unit")); reverse.param_update_default(prefs->getBool("/live_effects/measure-line/reverse")); color_as_line.param_update_default(prefs->getBool("/live_effects/measure-line/color_as_line")); scale_insensitive.param_update_default(prefs->getBool("/live_effects/measure-line/scale_insensitive")); + local_locale.param_update_default(prefs->getBool("/live_effects/measure-line/local_locale")); rtext = NULL; precision.param_set_range(0, 100); precision.param_set_increments(1, 1); @@ -92,9 +96,9 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : offset_top_bottom.param_set_range(-999999.0, 999999.0); offset_top_bottom.param_set_increments(1, 1); offset_top_bottom.param_set_digits(2); - line_offset.param_set_range(-999999.0, 999999.0); - line_offset.param_set_increments(1, 1); - line_offset.param_set_digits(2); + origin_offset.param_set_range(-999999.0, 999999.0); + origin_offset.param_set_increments(1, 1); + origin_offset.param_set_digits(2); gap_start.param_set_range(-999999.0, 999999.0); gap_start.param_set_increments(1, 1); gap_start.param_set_digits(2); @@ -104,6 +108,8 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : fontlister = Inkscape::FontLister::get_instance(); } +bool LPEMeasureLine::alerts_off = false; + LPEMeasureLine::~LPEMeasureLine() {} void @@ -113,6 +119,18 @@ LPEMeasureLine::doOnApply(SPLPEItem const* lpeitem) g_warning("LPE measure line can only be applied to shapes (not groups)."); SPLPEItem * item = const_cast(lpeitem); item->removeCurrentPathEffect(false); + } else { + if(!alerts_off) { + char *msg = _("The \"measure line\" path effect could update original path on the object you are applying it to if link it to other path. If this is not what you want, click Cancel."); + Gtk::MessageDialog dialog(msg, false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_OK_CANCEL, true); + gint response = dialog.run(); + alerts_off = true; + if(response == GTK_RESPONSE_CANCEL) { + SPLPEItem* item = const_cast(lpeitem); + item->removeCurrentPathEffect(false); + return; + } + } } } @@ -145,8 +163,8 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); if (angle_cross < 0) angle_cross += 2*M_PI; - s = s - Point::polar(angle_cross, line_offset); - e = e - Point::polar(angle_cross, line_offset); + s = s - Point::polar(angle_cross, origin_offset); + e = e - Point::polar(angle_cross, origin_offset); Geom::Path path; path.start( s ); path.appendNew( e ); @@ -249,17 +267,22 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } length = Inkscape::Util::Quantity::convert(length, doc_unit.c_str(), unit.get_abbreviation()); std::stringstream length_str; - length_str.imbue(std::locale::classic()); - length_str << "%." << precision << "f %s"; - gchar *lengthchar = g_strdup_printf(length_str.str().c_str(), length, unit.get_abbreviation()); + length_str.setf(std::ios::fixed, std::ios::floatfield); + length_str.precision(precision); + if (local_locale) { + length_str.imbue(std::locale("")); + } else { + length_str.imbue(std::locale::classic()); + } + length_str << length << unit.get_abbreviation(); Inkscape::XML::Node *rstring = NULL; if (!elemref) { - rstring = xml_doc->createTextNode(lengthchar); + rstring = xml_doc->createTextNode(length_str.str().c_str()); rtspan->addChild(rstring, NULL); Inkscape::GC::release(rstring); } else { rstring = rtspan->firstChild(); - rstring->setContent(lengthchar); + rstring->setContent(length_str.str().c_str()); } SPObject * text_obj = NULL; if (!elemref) { @@ -280,11 +303,13 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) void LPEMeasureLine::doOnRemove (SPLPEItem const* /*lpeitem*/) { if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { - rtext->setAttribute("sodipodi:insensitive", NULL); - SPObject * text_obj = desktop->currentLayer()->get_child_by_repr(rtext); - if (text_obj) { - text_obj->updateRepr(); - text_obj->deleteObject(); + if (rtext) { + rtext->setAttribute("sodipodi:insensitive", NULL); + SPObject * text_obj = desktop->currentLayer()->get_child_by_repr(rtext); + if (text_obj) { + text_obj->updateRepr(); + text_obj->deleteObject(); + } } } } @@ -297,7 +322,7 @@ Gtk::Widget *LPEMeasureLine::newWidget() vbox->set_border_width(5); vbox->set_homogeneous(false); - vbox->set_spacing(6); + vbox->set_spacing(2); std::vector::iterator it = param_vector.begin(); Gtk::HBox * button1 = Gtk::manage(new Gtk::HBox(true,0)); @@ -319,7 +344,7 @@ Gtk::Widget *LPEMeasureLine::newWidget() ++it; } - Gtk::Button *save_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Save as default")))); + Gtk::Button *save_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Save '*' as default")))); save_default->signal_clicked().connect(sigc::mem_fun(*this, &LPEMeasureLine::saveDefault)); button1->pack_start(*save_default, true, true, 2); vbox->pack_start(*button1, true, true, 2); @@ -356,11 +381,12 @@ LPEMeasureLine::saveDefault() prefs->setInt("/live_effects/measure-line/precision", precision); prefs->setDouble("/live_effects/measure-line/offset_right_left", offset_right_left); prefs->setDouble("/live_effects/measure-line/offset_top_bottom", offset_top_bottom); - prefs->setDouble("/live_effects/measure-line/line_offset", line_offset); + prefs->setDouble("/live_effects/measure-line/origin_offset", origin_offset); prefs->setString("/live_effects/measure-line/unit", (Glib::ustring)unit.get_abbreviation()); - prefs->setInt("/live_effects/measure-line/reverse", reverse); - prefs->setInt("/live_effects/measure-line/color_as_line", color_as_line); - prefs->setInt("/live_effects/measure-line/scale_insensitive", scale_insensitive); + prefs->setBool("/live_effects/measure-line/reverse", reverse); + prefs->setBool("/live_effects/measure-line/color_as_line", color_as_line); + prefs->setBool("/live_effects/measure-line/scale_insensitive", scale_insensitive); + prefs->setBool("/live_effects/measure-line/local_locale", local_locale); } }; //namespace LivePathEffect diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index b03a44705..75faee45d 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -45,7 +45,7 @@ private: Geom::Coord angle; OriginalPathParam origin; ScalarParam curve_linked; - ScalarParam line_offset; + ScalarParam origin_offset; ScalarParam scale; ScalarParam precision; ScalarParam offset_right_left; @@ -57,7 +57,9 @@ private: BoolParam reverse; BoolParam color_as_line; BoolParam scale_insensitive; + BoolParam local_locale; Glib::ustring doc_unit; + static bool alerts_off; /* Geom::Affine affine_over;*/ LPEMeasureLine(const LPEMeasureLine &); LPEMeasureLine &operator=(const LPEMeasureLine &); -- cgit v1.2.3 From 4450066e940f3751d1a69fdfc0efc8428dedfab2 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 28 Jul 2016 13:16:04 +0200 Subject: Fix little typo (bzr r15017.1.10) --- src/live_effects/lpe-measure-line.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 31b1db7c2..69d1619d8 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -37,7 +37,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : Effect(lpeobject), fontselector(_("Font Selector*"), _("Font Selector"), "fontselector", &wr, this, " "), origin(_("Optional Origin"), _("Optional origin"), "origin", &wr, this), - curve_linked(_("Curve on optional origin*"), _("Curve on optional origin, set 0 to start/end"), "curve_linked", &wr, this, 1), + curve_linked(_("Curve on optional origin"), _("Curve on optional origin, set 0 to start/end"), "curve_linked", &wr, this, 1), origin_offset(_("Optional origin offset*"), _("Optional origin offset"), "origin_offset", &wr, this, 5), scale(_("Scale*"), _("Scaling factor"), "scale", &wr, this, 1.0), precision(_("Number precision*"), _("Number precision"), "precision", &wr, this, 2), -- cgit v1.2.3 From 881b103a91e5668c1f7333ac989e4a968aa92aed Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 29 Jul 2016 12:06:16 +0200 Subject: Improvements to widget redraw (bzr r15017.1.11) --- src/live_effects/lpe-ellipse_5pts.cpp | 2 +- src/live_effects/lpe-extrude.cpp | 2 +- src/live_effects/lpe-knot.cpp | 4 ++-- src/live_effects/parameter/parameter.cpp | 38 +++++++++++++++++++++----------- src/live_effects/parameter/parameter.h | 2 ++ src/live_effects/parameter/point.cpp | 31 ++++++++++++++------------ src/live_effects/parameter/point.h | 2 ++ 7 files changed, 50 insertions(+), 31 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-ellipse_5pts.cpp b/src/live_effects/lpe-ellipse_5pts.cpp index 4c953bcda..088d24b9c 100644 --- a/src/live_effects/lpe-ellipse_5pts.cpp +++ b/src/live_effects/lpe-ellipse_5pts.cpp @@ -171,7 +171,7 @@ LPEEllipse5Pts::doEffect_path (Geom::PathVector const & path_in) // figure out if we have a slice, guarding against rounding errors - Path p(Geom::Point(cos(0), sin(0))); + Geom::Path p(Geom::Point(cos(0), sin(0))); double end = 2 * M_PI; for (s = 0; s < end; s += M_PI_2) { diff --git a/src/live_effects/lpe-extrude.cpp b/src/live_effects/lpe-extrude.cpp index 8b3f4714a..dd1a8c824 100644 --- a/src/live_effects/lpe-extrude.cpp +++ b/src/live_effects/lpe-extrude.cpp @@ -66,7 +66,7 @@ LPEExtrude::doEffect_pwd2 (Geom::Piecewise > const & pwd2 using namespace Geom; // generate connecting lines (the 'sides' of the extrusion) - Path path(Point(0.,0.)); + Geom::Path path(Point(0.,0.)); path.appendNew( extrude_vector.getVector() ); Piecewise > connector = path.toPwSb(); diff --git a/src/live_effects/lpe-knot.cpp b/src/live_effects/lpe-knot.cpp index a033a6c4a..09f35f05e 100644 --- a/src/live_effects/lpe-knot.cpp +++ b/src/live_effects/lpe-knot.cpp @@ -101,7 +101,7 @@ findShadowedTime(Geom::Path const &patha, std::vector const &pt_and Affine mat = from_basis( T, N, pt_and_dir[0] ); mat = mat.inverse(); - Path p = patha * mat; + Geom::Path p = patha * mat; std::vector times; @@ -484,7 +484,7 @@ LPEKnot::doEffect_path (Geom::PathVector const &path_in) // std::cout<<"fusing first and last component\n"; ++beg_comp; --end_comp; - Path first = gpaths[i0].portion(dom.back()); + Geom::Path first = gpaths[i0].portion(dom.back()); //FIXME: stitching should not be necessary (?!?) first.setStitching(true); first.append(gpaths[i0].portion(dom.front())); diff --git a/src/live_effects/parameter/parameter.cpp b/src/live_effects/parameter/parameter.cpp index ae55c84e9..3f8fced4b 100644 --- a/src/live_effects/parameter/parameter.cpp +++ b/src/live_effects/parameter/parameter.cpp @@ -4,8 +4,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include "ui/widget/registered-widget.h" -#include #include "live_effects/parameter/parameter.h" #include "live_effects/effect.h" @@ -16,6 +14,8 @@ #include "verbs.h" +#include + #define noLPEREALPARAM_DEBUG namespace Inkscape { @@ -66,7 +66,8 @@ ScalarParam::ScalarParam( const Glib::ustring& label, const Glib::ustring& tip, inc_page(1), add_slider(false), overwrite_widget(false), - hide_widget(no_widget) + hide_widget(no_widget), + _rsu(NULL) { } @@ -117,6 +118,9 @@ ScalarParam::param_set_value(gdouble val) value = max; if (value < min) value = min; + if (_rsu) { + _rsu->setValue(val); + } } void @@ -138,7 +142,9 @@ ScalarParam::param_set_range(gdouble min, gdouble max) } else { this->max = SCALARPARAM_G_MAXDOUBLE; } - + if (_rsu) { + _rsu->setRange(this->min, this->max); + } param_set_value(value); // reset value to see whether it is in ranges } @@ -161,22 +167,22 @@ Gtk::Widget * ScalarParam::param_newWidget() { if(!hide_widget){ - Inkscape::UI::Widget::RegisteredScalar *rsu = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalar( + _rsu = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalar( param_label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc() ) ); - rsu->setValue(value); - rsu->setDigits(digits); - rsu->setIncrements(inc_step, inc_page); - rsu->setRange(min, max); - rsu->setProgrammatically = false; + _rsu->setValue(value); + _rsu->setDigits(digits); + _rsu->setIncrements(inc_step, inc_page); + _rsu->setRange(min, max); + _rsu->setProgrammatically = false; if (add_slider) { - rsu->addSlider(); + _rsu->addSlider(); } if(!overwrite_widget){ - rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change scalar parameter")); + _rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change scalar parameter")); } param_effect->upd_params = false; - return dynamic_cast (rsu); + return dynamic_cast (_rsu); } else { return NULL; } @@ -186,6 +192,9 @@ void ScalarParam::param_set_digits(unsigned digits) { this->digits = digits; + if (_rsu) { + _rsu->setDigits(this->digits); + } } void @@ -193,6 +202,9 @@ ScalarParam::param_set_increments(double step, double page) { inc_step = step; inc_page = page; + if (_rsu) { + _rsu->setIncrements(inc_step, inc_page); + } } diff --git a/src/live_effects/parameter/parameter.h b/src/live_effects/parameter/parameter.h index 8556b0d9a..63c55203e 100644 --- a/src/live_effects/parameter/parameter.h +++ b/src/live_effects/parameter/parameter.h @@ -12,6 +12,7 @@ #include #include <2geom/forward.h> #include <2geom/pathvector.h> +#include "ui/widget/registered-widget.h" // In gtk2, this wasn't an issue; we could toss around // G_MAXDOUBLE and not worry about size allocations. But @@ -140,6 +141,7 @@ protected: private: ScalarParam(const ScalarParam&); ScalarParam& operator=(const ScalarParam&); + Inkscape::UI::Widget::RegisteredScalar *_rsu; }; } //namespace LivePathEffect diff --git a/src/live_effects/parameter/point.cpp b/src/live_effects/parameter/point.cpp index 90a5b252b..3442fd851 100644 --- a/src/live_effects/parameter/point.cpp +++ b/src/live_effects/parameter/point.cpp @@ -4,7 +4,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include "ui/widget/registered-widget.h" #include "live_effects/parameter/point.h" #include "live_effects/effect.h" #include "svg/svg.h" @@ -30,7 +29,8 @@ PointParam::PointParam( const Glib::ustring& label, const Glib::ustring& tip, : Parameter(label, tip, key, wr, effect), defvalue(default_value), liveupdate(live_update), - knoth(NULL) + knoth(NULL), + _pointwdg(NULL) { knot_shape = SP_KNOT_SHAPE_DIAMOND; knot_mode = SP_KNOT_MODE_XOR; @@ -81,6 +81,9 @@ PointParam::param_setValue(Geom::Point newpoint, bool write) if(knoth && liveupdate){ knoth->update_knots(); } + if (_pointwdg) { + _pointwdg->setValue( newpoint ); + } } bool @@ -116,7 +119,7 @@ PointParam::param_transform_multiply(Geom::Affine const& postmul, bool /*set*/) Gtk::Widget * PointParam::param_newWidget() { - Inkscape::UI::Widget::RegisteredTransformedPoint * pointwdg = Gtk::manage( + _pointwdg = Gtk::manage( new Inkscape::UI::Widget::RegisteredTransformedPoint( param_label, param_tooltip, param_key, @@ -126,13 +129,13 @@ PointParam::param_newWidget() // TODO: fix to get correct desktop (don't use SP_ACTIVE_DESKTOP) SPDesktop *desktop = SP_ACTIVE_DESKTOP; Geom::Affine transf = desktop->doc2dt(); - pointwdg->setTransform(transf); - pointwdg->setValue( *this ); - pointwdg->clearProgrammatically(); - pointwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change point parameter")); + _pointwdg->setTransform(transf); + _pointwdg->setValue( *this ); + _pointwdg->clearProgrammatically(); + _pointwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change point parameter")); Gtk::HBox * hbox = Gtk::manage( new Gtk::HBox() ); - static_cast(hbox)->pack_start(*pointwdg, true, true); + static_cast(hbox)->pack_start(*_pointwdg, true, true); static_cast(hbox)->show_all_children(); param_effect->upd_params = false; return dynamic_cast (hbox); @@ -191,13 +194,13 @@ void PointParamKnotHolderEntity::knot_click(guint state) { if (state & GDK_CONTROL_MASK) { - if (state & GDK_MOD1_MASK) { - this->pparam->param_set_default(); - SPLPEItem * splpeitem = dynamic_cast(item); - if(splpeitem){ - sp_lpe_item_update_patheffect(splpeitem, false, false); - } + if (state & GDK_MOD1_MASK) { + this->pparam->param_set_default(); + SPLPEItem * splpeitem = dynamic_cast(item); + if(splpeitem){ + sp_lpe_item_update_patheffect(splpeitem, false, false); } + } } } diff --git a/src/live_effects/parameter/point.h b/src/live_effects/parameter/point.h index d41e8a710..62c6fb83d 100644 --- a/src/live_effects/parameter/point.h +++ b/src/live_effects/parameter/point.h @@ -11,6 +11,7 @@ #include #include <2geom/point.h> +#include "ui/widget/registered-widget.h" #include "live_effects/parameter/parameter.h" #include "knot-holder-entity.h" @@ -61,6 +62,7 @@ private: SPKnotModeType knot_mode; guint32 knot_color; gchar *handle_tip; + Inkscape::UI::Widget::RegisteredTransformedPoint * _pointwdg; }; -- cgit v1.2.3 From 53500549df51879d6a7aaec5a0c8c37ca7087817 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 29 Jul 2016 20:28:00 +0200 Subject: Add orientation and alow unsort combobox enum widget (bzr r15017.1.12) --- src/live_effects/lpe-measure-line.cpp | 437 ++++++++++++++++++++++------------ src/live_effects/lpe-measure-line.h | 19 +- src/live_effects/parameter/enum.h | 8 +- 3 files changed, 303 insertions(+), 161 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 69d1619d8..6145f7592 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -8,6 +8,7 @@ */ #include "live_effects/lpe-measure-line.h" #include "inkscape.h" +#include "xml/node.h" #include "uri.h" #include "uri-references.h" #include "preferences.h" @@ -33,9 +34,21 @@ using namespace Geom; namespace Inkscape { namespace LivePathEffect { +static const Util::EnumData OrientationMethodData[] = { + { OM_HORIZONTAL, N_("Horizontal"), "horizontal" }, + { OM_VERTICAL, N_("Vertical"), "vertical" }, + { OM_PARALLEL, N_("Parallel"), "parallel" }, + { OM_PARALLEL_VERTICAL, N_("Parallel and vertical,"), "parallel_vertical" }, + { OM_PARALLEL_HORIZONTAL, N_("Parallel and horizontal"), "parallel_horizontal" }, + { OM_VERTICAL_HORIZONTAL, N_("Vertical and horizontal"), "vertical_horizontal" }, + { OM_PARALLEL_VERTICAL_HORIZONTAL, N_("Parallel, vertical and horizontal"), "parallel_vertical_horizontal" } +}; +static const Util::EnumDataConverter OMConverter(OrientationMethodData, OM_END); + LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : Effect(lpeobject), fontselector(_("Font Selector*"), _("Font Selector"), "fontselector", &wr, this, " "), + orientation(_("Orientation"), _("Orientation method"), "orientation", OMConverter, &wr, this, OM_PARALLEL, false), origin(_("Optional Origin"), _("Optional origin"), "origin", &wr, this), curve_linked(_("Curve on optional origin"), _("Curve on optional origin, set 0 to start/end"), "curve_linked", &wr, this, 1), origin_offset(_("Optional origin offset*"), _("Optional origin offset"), "origin_offset", &wr, this, 5), @@ -49,11 +62,10 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : reverse(_("To other side*"), _("To other side"), "reverse", &wr, this, false), color_as_line(_("Measure color as line*"), _("Measure color as line"), "color_as_line", &wr, this, false), scale_insensitive(_("Scale insensitive*"), _("Scale insensitive to transforms in element, parents..."), "scale_insensitive", &wr, this, true), - local_locale(_("Local Number Format*"), _("Local number format"), "local_locale", &wr, this, true), - pos(0,0), - angle(0) + local_locale(_("Local Number Format*"), _("Local number format"), "local_locale", &wr, this, true) { registerParameter(&fontselector); + registerParameter(&orientation); registerParameter(&origin); registerParameter(&curve_linked); registerParameter(&origin_offset); @@ -80,7 +92,6 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : color_as_line.param_update_default(prefs->getBool("/live_effects/measure-line/color_as_line")); scale_insensitive.param_update_default(prefs->getBool("/live_effects/measure-line/scale_insensitive")); local_locale.param_update_default(prefs->getBool("/live_effects/measure-line/local_locale")); - rtext = NULL; precision.param_set_range(0, 100); precision.param_set_increments(1, 1); precision.param_set_digits(0); @@ -143,175 +154,279 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) Geom::PathVector pathvector = sp_path->get_original_curve()->get_pathvector(); if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); - Geom::Point s = pathvector.initialPoint(); - Geom::Point e = pathvector.finalPoint(); - if (origin.linksToPath() && origin.getObject() && !origin.get_pathvector().empty()) { - pathvector = origin.get_pathvector(); - size_t ncurves = pathvector.curveCount(); - curve_linked.param_set_range(1, ncurves); - if(previous_ncurves != ncurves) { - this->upd_params = true; - previous_ncurves = ncurves; + std::vector orientations; + std::vector orientations_remove; + if ( orientation == OM_HORIZONTAL || + orientation == OM_PARALLEL_VERTICAL_HORIZONTAL || + orientation == OM_PARALLEL_HORIZONTAL || + orientation == OM_VERTICAL_HORIZONTAL) + { + orientations.push_back(OM_HORIZONTAL); + } else { + orientations_remove.push_back(OM_HORIZONTAL); + } + if ( orientation == OM_VERTICAL || + orientation == OM_PARALLEL_VERTICAL_HORIZONTAL || + orientation == OM_PARALLEL_VERTICAL || + orientation == OM_VERTICAL_HORIZONTAL) + { + orientations.push_back(OM_VERTICAL); + } else { + orientations_remove.push_back(OM_VERTICAL); + } + if ( orientation == OM_PARALLEL || + orientation == OM_PARALLEL_VERTICAL_HORIZONTAL || + orientation == OM_PARALLEL_VERTICAL || + orientation == OM_PARALLEL_HORIZONTAL) + { + orientations.push_back(OM_PARALLEL); + } else { + orientations_remove.push_back(OM_PARALLEL); + } + for (std::vector::const_iterator om_it = orientations.begin(); om_it != orientations.end(); ++om_it) { + Geom::Point s = pathvector.initialPoint(); + Geom::Point e = pathvector.finalPoint(); + Glib::ustring orientation_str; + Inkscape::XML::Node *rtext = NULL; + if (*om_it == OM_VERTICAL) { + orientation_str = "vertical"; + } + if (*om_it == OM_HORIZONTAL) { + orientation_str = "horizontal"; } - s = pathvector.pointAt(curve_linked -1); - e = pathvector.pointAt(curve_linked); + if (*om_it == OM_PARALLEL) { + orientation_str = "parallel"; + } + if (origin.linksToPath() && origin.getObject() && !origin.get_pathvector().empty()) { + pathvector = origin.get_pathvector(); + size_t ncurves = pathvector.curveCount(); + curve_linked.param_set_range(1, ncurves); + if(previous_ncurves != ncurves) { + this->upd_params = true; + previous_ncurves = ncurves; + } + s = pathvector.pointAt(curve_linked -1); + e = pathvector.pointAt(curve_linked); + if(*om_it == OM_VERTICAL) { + Coord xpos = std::max(s[Geom::X],e[Geom::X]); + if (reverse) { + xpos = std::min(s[Geom::X],e[Geom::X]); + } + s[Geom::X] = xpos; + e[Geom::X] = xpos; + } + if(*om_it == OM_HORIZONTAL) { + Coord ypos = std::max(s[Geom::Y],e[Geom::Y]); + if (reverse) { + ypos = std::min(s[Geom::Y],e[Geom::Y]); + } + s[Geom::Y] = ypos; + e[Geom::Y] = ypos; + } + Geom::Ray ray(s,e); + Geom::Coord angle = ray.angle(); + if (reverse) { + angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); + if (angle < 0) angle += 2*M_PI; + } + Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); + if (angle_cross < 0) angle_cross += 2*M_PI; + s = s - Point::polar(angle_cross, origin_offset); + e = e - Point::polar(angle_cross, origin_offset); + Geom::Path path; + path.start( s ); + path.appendNew( e ); + Geom::PathVector line_upd; + line_upd.push_back(path); + Inkscape::XML::Node *line = SP_OBJECT(sp_path)->getRepr(); + gchar *str = sp_svg_write_path(line_upd); + line->setAttribute("inkscape:original-d", str); + } else { + if(*om_it == OM_VERTICAL) { + Coord xpos = std::max(s[Geom::X],e[Geom::X]); + if (reverse) { + xpos = std::min(s[Geom::X],e[Geom::X]); + } + s[Geom::X] = xpos; + e[Geom::X] = xpos; + } + if(*om_it == OM_HORIZONTAL) { + Coord ypos = std::max(s[Geom::Y],e[Geom::Y]); + if (reverse) { + ypos = std::min(s[Geom::Y],e[Geom::Y]); + } + s[Geom::Y] = ypos; + e[Geom::Y] = ypos; + } + } + double length = Geom::distance(s, e) * scale; + Geom::Point pos = Geom::middle_point(s,e); Geom::Ray ray(s,e); - angle = ray.angle(); + Geom::Coord angle = ray.angle(); + doc_unit = Inkscape::Util::unit_table.getUnit(desktop->doc()->getRoot()->height.unit)->abbr; if (reverse) { angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); if (angle < 0) angle += 2*M_PI; } + Geom::Point newpos = pos - Point::polar(angle, offset_right_left); Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); if (angle_cross < 0) angle_cross += 2*M_PI; - s = s - Point::polar(angle_cross, origin_offset); - e = e - Point::polar(angle_cross, origin_offset); - Geom::Path path; - path.start( s ); - path.appendNew( e ); - Geom::PathVector line_upd; - line_upd.push_back(path); - Inkscape::XML::Node *line = SP_OBJECT(sp_path)->getRepr(); - gchar *str = sp_svg_write_path(line_upd); - line->setAttribute("inkscape:original-d", str); - } - length = Geom::distance(s, e) * scale; - pos = Geom::middle_point(s,e); - Geom::Ray ray(s,e); - angle = ray.angle(); - doc_unit = Inkscape::Util::unit_table.getUnit(desktop->doc()->getRoot()->height.unit)->abbr; - if (reverse) { - angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); - if (angle < 0) angle += 2*M_PI; - } - Geom::Point newpos = pos - Point::polar(angle, offset_right_left); - Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); - if (angle_cross < 0) angle_cross += 2*M_PI; - newpos = newpos - Point::polar(angle_cross, offset_top_bottom); - Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_mlsize").c_str()); - Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); - SVGElemRef->attach(SVGElem_uri); - SPObject *elemref = NULL; - Inkscape::XML::Node *rtspan = NULL; - if (elemref = SVGElemRef->getObject()) { - rtext = elemref->getRepr(); - sp_repr_set_svg_double(rtext, "x", newpos[Geom::X]); - sp_repr_set_svg_double(rtext, "y", newpos[Geom::Y]); - } else { - rtext = xml_doc->createElement("svg:text"); - rtext->setAttribute("xml:space", "preserve"); - rtext->setAttribute("sodipodi:insensitive", "true"); - rtext->setAttribute("id", ((Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_mlsize").c_str()); - /* Set style */ - sp_repr_set_svg_double(rtext, "x", newpos[Geom::X]); - sp_repr_set_svg_double(rtext, "y", newpos[Geom::Y]); - /* Create */ - rtspan = xml_doc->createElement("svg:tspan"); - rtspan->setAttribute("sodipodi:role", "line"); - } - SPCSSAttr *css = sp_repr_css_attr_new(); - Glib::ustring fontspec = fontselector.param_readFontSpec(fontselector.param_getSVGValue()); - double fontsize = fontselector.param_readFontSize(fontselector.param_getSVGValue()); - fontlister->fill_css( css, fontspec ); - std::stringstream font_size; - font_size.imbue(std::locale::classic()); - font_size << fontsize << "pt"; - sp_repr_css_set_property (css, "font-size", font_size.str().c_str()); - sp_repr_css_set_property (css, "font-style", "normal"); - sp_repr_css_set_property (css, "font-weight", "normal"); - sp_repr_css_set_property (css, "line-height", "125%"); - sp_repr_css_set_property (css, "letter-spacing", "0"); - sp_repr_css_set_property (css, "word-spacing", "0"); - sp_repr_css_set_property (css, "text-align", "center"); - sp_repr_css_set_property (css, "text-anchor", "middle"); - if (color_as_line) { - if (lpeitem->style) { - if (lpeitem->style->stroke.isPaintserver()) { - SPPaintServer * server = lpeitem->style->getStrokePaintServer(); - if (server) { - Glib::ustring str; - str += "url(#"; - str += server->getId(); - str += ")"; - sp_repr_css_set_property (css, "fill", str.c_str()); + newpos = newpos - Point::polar(angle_cross, offset_top_bottom); + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_DINnumber_" + orientation_str).c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + Inkscape::XML::Node *rtspan = NULL; + if (elemref = SVGElemRef->getObject()) { + rtext = elemref->getRepr(); + sp_repr_set_svg_double(rtext, "x", newpos[Geom::X]); + sp_repr_set_svg_double(rtext, "y", newpos[Geom::Y]); + } else { + rtext = xml_doc->createElement("svg:text"); + rtext->setAttribute("xml:space", "preserve"); + rtext->setAttribute("sodipodi:insensitive", "true"); + rtext->setAttribute("id", ((Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_DINnumber_" + orientation_str).c_str()); + /* Set style */ + sp_repr_set_svg_double(rtext, "x", newpos[Geom::X]); + sp_repr_set_svg_double(rtext, "y", newpos[Geom::Y]); + /* Create */ + rtspan = xml_doc->createElement("svg:tspan"); + rtspan->setAttribute("sodipodi:role", "line"); + } + SPCSSAttr *css = sp_repr_css_attr_new(); + Glib::ustring fontspec = fontselector.param_readFontSpec(fontselector.param_getSVGValue()); + double fontsize = fontselector.param_readFontSize(fontselector.param_getSVGValue()); + fontlister->fill_css( css, fontspec ); + std::stringstream font_size; + font_size.imbue(std::locale::classic()); + font_size << fontsize << "pt"; + sp_repr_css_set_property (css, "font-size", font_size.str().c_str()); + sp_repr_css_set_property (css, "font-style", "normal"); + sp_repr_css_set_property (css, "font-weight", "normal"); + sp_repr_css_set_property (css, "line-height", "125%"); + sp_repr_css_set_property (css, "letter-spacing", "0"); + sp_repr_css_set_property (css, "word-spacing", "0"); + sp_repr_css_set_property (css, "text-align", "center"); + sp_repr_css_set_property (css, "text-anchor", "middle"); + if (color_as_line) { + if (lpeitem->style) { + if (lpeitem->style->stroke.isPaintserver()) { + SPPaintServer * server = lpeitem->style->getStrokePaintServer(); + if (server) { + Glib::ustring str; + str += "url(#"; + str += server->getId(); + str += ")"; + sp_repr_css_set_property (css, "fill", str.c_str()); + } + } else if (lpeitem->style->stroke.isColor()) { + gchar c[64]; + sp_svg_write_color (c, sizeof(c), lpeitem->style->stroke.value.color.toRGBA32(SP_SCALE24_TO_FLOAT(lpeitem->style->stroke_opacity.value))); + sp_repr_css_set_property (css, "fill", c); + } else { + sp_repr_css_set_property (css, "fill", "#000000"); } - } else if (lpeitem->style->stroke.isColor()) { - gchar c[64]; - sp_svg_write_color (c, sizeof(c), lpeitem->style->stroke.value.color.toRGBA32(SP_SCALE24_TO_FLOAT(lpeitem->style->stroke_opacity.value))); - sp_repr_css_set_property (css, "fill", c); } else { - sp_repr_css_set_property (css, "fill", "#000000"); + sp_repr_css_unset_property (css, "#000000"); } } else { - sp_repr_css_unset_property (css, "#000000"); + sp_repr_css_set_property (css, "fill", "#000000"); } - } else { - sp_repr_css_set_property (css, "fill", "#000000"); - } - sp_repr_css_set_property (css, "fill-opacity", "1"); - sp_repr_css_set_property (css, "stroke", "none"); - Glib::ustring css_str; - sp_repr_css_write_string(css,css_str); - if (!rtspan) { - rtspan = rtext->firstChild(); - } - rtspan->setAttribute("style", css_str.c_str()); - sp_repr_css_attr_unref (css); - if (!elemref) { - rtext->addChild(rtspan, NULL); - Inkscape::GC::release(rtspan); - } - /* Create TEXT */ - if (!scale_insensitive) { - Geom::Affine affinetransform = i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(desktop->doc()->getRoot())); - length *= (affinetransform.expansionX() + affinetransform.expansionY()) / 2.0; - } - length = Inkscape::Util::Quantity::convert(length, doc_unit.c_str(), unit.get_abbreviation()); - std::stringstream length_str; - length_str.setf(std::ios::fixed, std::ios::floatfield); - length_str.precision(precision); - if (local_locale) { - length_str.imbue(std::locale("")); - } else { - length_str.imbue(std::locale::classic()); - } - length_str << length << unit.get_abbreviation(); - Inkscape::XML::Node *rstring = NULL; - if (!elemref) { - rstring = xml_doc->createTextNode(length_str.str().c_str()); - rtspan->addChild(rstring, NULL); - Inkscape::GC::release(rstring); - } else { - rstring = rtspan->firstChild(); - rstring->setContent(length_str.str().c_str()); + sp_repr_css_set_property (css, "fill-opacity", "1"); + sp_repr_css_set_property (css, "stroke", "none"); + Glib::ustring css_str; + sp_repr_css_write_string(css,css_str); + if (!rtspan) { + rtspan = rtext->firstChild(); + } + rtspan->setAttribute("style", css_str.c_str()); + sp_repr_css_attr_unref (css); + if (!elemref) { + rtext->addChild(rtspan, NULL); + Inkscape::GC::release(rtspan); + } + /* Create TEXT */ + if (!scale_insensitive) { + Geom::Affine affinetransform = i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(desktop->doc()->getRoot())); + length *= (affinetransform.expansionX() + affinetransform.expansionY()) / 2.0; + } + length = Inkscape::Util::Quantity::convert(length, doc_unit.c_str(), unit.get_abbreviation()); + std::stringstream length_str; + length_str.setf(std::ios::fixed, std::ios::floatfield); + length_str.precision(precision); + if (local_locale) { + length_str.imbue(std::locale("")); + } else { + length_str.imbue(std::locale::classic()); + } + length_str << length << unit.get_abbreviation(); + Inkscape::XML::Node *rstring = NULL; + if (!elemref) { + rstring = xml_doc->createTextNode(length_str.str().c_str()); + rtspan->addChild(rstring, NULL); + Inkscape::GC::release(rstring); + } else { + rstring = rtspan->firstChild(); + rstring->setContent(length_str.str().c_str()); + } + SPObject * text_obj = NULL; + if (!elemref) { + text_obj = SP_OBJECT(desktop->currentLayer()->appendChildRepr(rtext)); + Inkscape::GC::release(rtext); + } else { + text_obj = desktop->currentLayer()->get_child_by_repr(rtext); + } + Geom::Affine affine = Geom::Affine(Geom::Translate(newpos).inverse()); + affine *= Geom::Rotate(angle); + affine *= Geom::Translate(newpos); + SP_ITEM(text_obj)->transform = affine * i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(desktop->doc()->getRoot())); + text_obj->updateRepr(); } - SPObject * text_obj = NULL; - if (!elemref) { - text_obj = SP_OBJECT(desktop->currentLayer()->appendChildRepr(rtext)); - Inkscape::GC::release(rtext); - } else { - text_obj = desktop->currentLayer()->get_child_by_repr(rtext); + for (std::vector::const_iterator omdel_it = orientations_remove.begin(); omdel_it != orientations_remove.end(); ++omdel_it) { + Glib::ustring orientation_str; + if (*omdel_it == OM_VERTICAL) { + orientation_str = "vertical"; + } + if (*omdel_it == OM_HORIZONTAL) { + orientation_str = "horizontal"; + } + if (*omdel_it == OM_PARALLEL) { + orientation_str = "parallel"; + } + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_DINnumber_" + orientation_str).c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + if (elemref = SVGElemRef->getObject()) { + elemref->deleteObject(); + } } - Geom::Affine affine = Geom::Affine(Geom::Translate(newpos).inverse()); - affine *= Geom::Rotate(angle); - affine *= Geom::Translate(newpos); - SP_ITEM(text_obj)->transform = affine * i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(desktop->doc()->getRoot())); - text_obj->updateRepr(); } } } void LPEMeasureLine::doOnRemove (SPLPEItem const* /*lpeitem*/) { - if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { - if (rtext) { - rtext->setAttribute("sodipodi:insensitive", NULL); - SPObject * text_obj = desktop->currentLayer()->get_child_by_repr(rtext); - if (text_obj) { - text_obj->updateRepr(); - text_obj->deleteObject(); - } - } - } +// if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { +// if (horizontal_text) { +// SPObject * text_obj = desktop->currentLayer()->get_child_by_repr(horizontal_text); +// if (text_obj) { +// text_obj->deleteObject(); +// } +// } +// if (vertical_text) { +// SPObject * text_obj = desktop->currentLayer()->get_child_by_repr(vertical_text); +// if (text_obj) { +// text_obj->deleteObject(); +// } +// } +// if (parallel_text) { +// SPObject * text_obj = desktop->currentLayer()->get_child_by_repr(parallel_text); +// if (text_obj) { +// text_obj->deleteObject(); +// } +// } +// } } Gtk::Widget *LPEMeasureLine::newWidget() @@ -357,6 +472,8 @@ LPEMeasureLine::doEffect_path(Geom::PathVector const &path_in) Geom::Path path; Geom::Point s = path_in.initialPoint(); Geom::Point e = path_in.finalPoint(); + Geom::Ray ray(s,e); + Geom::Coord angle = ray.angle(); if (reverse) { angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); if (angle < 0) angle += 2*M_PI; @@ -365,6 +482,22 @@ LPEMeasureLine::doEffect_path(Geom::PathVector const &path_in) angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); if (angle < 0) angle += 2*M_PI; e = e - Point::polar(angle, gap_end); + if(orientation == OM_VERTICAL) { + Coord xpos = std::max(s[Geom::X],e[Geom::X]); + if (reverse) { + xpos = std::min(s[Geom::X],e[Geom::X]); + } + s[Geom::X] = xpos; + e[Geom::X] = xpos; + } + if(orientation == OM_HORIZONTAL) { + Coord ypos = std::max(s[Geom::Y],e[Geom::Y]); + if (reverse) { + ypos = std::min(s[Geom::Y],e[Geom::Y]); + } + s[Geom::Y] = ypos; + e[Geom::Y] = ypos; + } path.start( s ); path.appendNew( e ); Geom::PathVector output; diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index 75faee45d..67d27408a 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -11,6 +11,7 @@ */ #include "live_effects/effect.h" +#include "live_effects/parameter/enum.h" #include "live_effects/parameter/font.h" #include "live_effects/parameter/text.h" #include "live_effects/parameter/unit.h" @@ -20,12 +21,21 @@ #include <2geom/angle.h> #include <2geom/ray.h> #include <2geom/point.h> -#include "xml/node.h" - namespace Inkscape { namespace LivePathEffect { +enum OrientationMethod { + OM_HORIZONTAL, + OM_VERTICAL, + OM_PARALLEL, + OM_PARALLEL_VERTICAL, + OM_PARALLEL_HORIZONTAL, + OM_VERTICAL_HORIZONTAL, + OM_PARALLEL_VERTICAL_HORIZONTAL, + OM_END +}; + class LPEMeasureLine : public Effect { public: LPEMeasureLine(LivePathEffectObject *lpeobject); @@ -37,12 +47,9 @@ public: void saveDefault(); virtual Gtk::Widget *newWidget(); private: - double length; FontParam fontselector; Inkscape::FontLister *fontlister; - Inkscape::XML::Node *rtext; - Geom::Point pos; - Geom::Coord angle; + EnumParam orientation; OriginalPathParam origin; ScalarParam curve_linked; ScalarParam origin_offset; diff --git a/src/live_effects/parameter/enum.h b/src/live_effects/parameter/enum.h index 2340663c3..dbfc68623 100644 --- a/src/live_effects/parameter/enum.h +++ b/src/live_effects/parameter/enum.h @@ -27,12 +27,14 @@ public: const Util::EnumDataConverter& c, Inkscape::UI::Widget::Registry* wr, Effect* effect, - E default_value) + E default_value, + bool sort = true) : Parameter(label, tip, key, wr, effect) { enumdataconv = &c; defvalue = default_value; value = defvalue; + sorted = sort; }; virtual ~EnumParam() { }; @@ -40,12 +42,11 @@ public: virtual Gtk::Widget * param_newWidget() { Inkscape::UI::Widget::RegisteredEnum *regenum = Gtk::manage ( new Inkscape::UI::Widget::RegisteredEnum( param_label, param_tooltip, - param_key, *enumdataconv, *param_wr, param_effect->getRepr(), param_effect->getSPDoc() ) ); + param_key, *enumdataconv, *param_wr, param_effect->getRepr(), param_effect->getSPDoc(), sorted ) ); regenum->set_active_by_id(value); regenum->combobox()->setProgrammatically = false; regenum->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change enumeration parameter")); - return dynamic_cast (regenum); }; @@ -86,6 +87,7 @@ private: E value; E defvalue; + bool sorted; const Util::EnumDataConverter * enumdataconv; }; -- cgit v1.2.3 From d60fb000cfc3717ef51b716d9ccb9b63ecb38aa8 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 30 Jul 2016 01:44:17 +0200 Subject: Remove font-Dialog and useGtk::FontSelector instead (bzr r15017.1.13) --- src/live_effects/CMakeLists.txt | 4 +- src/live_effects/lpe-measure-line.cpp | 27 +++--- src/live_effects/lpe-measure-line.h | 5 +- src/live_effects/parameter/Makefile_insert | 2 + src/live_effects/parameter/font.cpp | 129 ----------------------------- src/live_effects/parameter/font.h | 78 ----------------- src/live_effects/parameter/fontbutton.cpp | 92 ++++++++++++++++++++ src/live_effects/parameter/fontbutton.h | 62 ++++++++++++++ 8 files changed, 174 insertions(+), 225 deletions(-) delete mode 100644 src/live_effects/parameter/font.cpp delete mode 100644 src/live_effects/parameter/font.h create mode 100644 src/live_effects/parameter/fontbutton.cpp create mode 100644 src/live_effects/parameter/fontbutton.h (limited to 'src/live_effects') diff --git a/src/live_effects/CMakeLists.txt b/src/live_effects/CMakeLists.txt index c3d740862..784317090 100644 --- a/src/live_effects/CMakeLists.txt +++ b/src/live_effects/CMakeLists.txt @@ -69,7 +69,7 @@ set(live_effects_SRC parameter/powerstrokepointarray.cpp parameter/random.cpp parameter/text.cpp - parameter/font.cpp + parameter/fontbutton.cpp parameter/togglebutton.cpp parameter/transformedpoint.cpp parameter/unit.cpp @@ -151,7 +151,7 @@ set(live_effects_SRC parameter/powerstrokepointarray.h parameter/random.h parameter/text.h - parameter/font.h + parameter/fontbutton.h parameter/togglebutton.h parameter/transformedpoint.h parameter/unit.h diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 6145f7592..5df3d499e 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -7,6 +7,8 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ #include "live_effects/lpe-measure-line.h" +#include +#include #include "inkscape.h" #include "xml/node.h" #include "uri.h" @@ -47,13 +49,13 @@ static const Util::EnumDataConverter OMConverter(OrientationM LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : Effect(lpeobject), - fontselector(_("Font Selector*"), _("Font Selector"), "fontselector", &wr, this, " "), + fontbutton(_("Font*"), _("Font Selector"), "fontbutton", &wr, this), orientation(_("Orientation"), _("Orientation method"), "orientation", OMConverter, &wr, this, OM_PARALLEL, false), origin(_("Optional Origin"), _("Optional origin"), "origin", &wr, this), curve_linked(_("Curve on optional origin"), _("Curve on optional origin, set 0 to start/end"), "curve_linked", &wr, this, 1), origin_offset(_("Optional origin offset*"), _("Optional origin offset"), "origin_offset", &wr, this, 5), scale(_("Scale*"), _("Scaling factor"), "scale", &wr, this, 1.0), - precision(_("Number precision*"), _("Number precision"), "precision", &wr, this, 2), + precision(_("Precision*"), _("Precision"), "precision", &wr, this, 2), offset_right_left(_("Offset right left*"), _("Offset right left"), "offset_right_left", &wr, this, 0), offset_top_bottom(_("Offset top bottom*"), _("Offset top bottom"), "offset_top_bottom", &wr, this, 5), gap_start(_("Gap to line from origin"), _("Gap to line from origin, without affecting measure"), "gap_start", &wr, this, 0), @@ -64,7 +66,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : scale_insensitive(_("Scale insensitive*"), _("Scale insensitive to transforms in element, parents..."), "scale_insensitive", &wr, this, true), local_locale(_("Local Number Format*"), _("Local number format"), "local_locale", &wr, this, true) { - registerParameter(&fontselector); + registerParameter(&fontbutton); registerParameter(&orientation); registerParameter(&origin); registerParameter(&curve_linked); @@ -81,7 +83,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : registerParameter(&scale_insensitive); registerParameter(&local_locale); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - fontselector.param_update_default(prefs->getString("/live_effects/measure-line/fontselector")); + fontbutton.param_update_default(prefs->getString("/live_effects/measure-line/fontbutton")); scale.param_update_default(prefs->getDouble("/live_effects/measure-line/scale", 1.0)); precision.param_update_default(prefs->getInt("/live_effects/measure-line/precision", 2)); offset_right_left.param_update_default(prefs->getDouble("/live_effects/measure-line/offset_right_left", 0.0)); @@ -116,7 +118,6 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : gap_end.param_set_range(-999999.0, 999999.0); gap_end.param_set_increments(1, 1); gap_end.param_set_digits(2); - fontlister = Inkscape::FontLister::get_instance(); } bool LPEMeasureLine::alerts_off = false; @@ -294,15 +295,14 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) rtspan->setAttribute("sodipodi:role", "line"); } SPCSSAttr *css = sp_repr_css_attr_new(); - Glib::ustring fontspec = fontselector.param_readFontSpec(fontselector.param_getSVGValue()); - double fontsize = fontselector.param_readFontSize(fontselector.param_getSVGValue()); - fontlister->fill_css( css, fontspec ); + Pango::FontDescription fontdesc((Glib::ustring)fontbutton.param_getSVGValue()); + double fontsize = fontdesc.get_size()/Pango::SCALE; + Inkscape::FontLister *fontlister = Inkscape::FontLister::get_instance(); + fontlister->fill_css( css, (Glib::ustring)fontbutton.param_getSVGValue() ); std::stringstream font_size; font_size.imbue(std::locale::classic()); font_size << fontsize << "pt"; sp_repr_css_set_property (css, "font-size", font_size.str().c_str()); - sp_repr_css_set_property (css, "font-style", "normal"); - sp_repr_css_set_property (css, "font-weight", "normal"); sp_repr_css_set_property (css, "line-height", "125%"); sp_repr_css_set_property (css, "letter-spacing", "0"); sp_repr_css_set_property (css, "word-spacing", "0"); @@ -352,14 +352,15 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } length = Inkscape::Util::Quantity::convert(length, doc_unit.c_str(), unit.get_abbreviation()); std::stringstream length_str; - length_str.setf(std::ios::fixed, std::ios::floatfield); length_str.precision(precision); + length_str.setf(std::ios::fixed, std::ios::floatfield); if (local_locale) { length_str.imbue(std::locale("")); } else { length_str.imbue(std::locale::classic()); } - length_str << length << unit.get_abbreviation(); + length_str << std::fixed << length; + length_str << unit.get_abbreviation(); Inkscape::XML::Node *rstring = NULL; if (!elemref) { rstring = xml_doc->createTextNode(length_str.str().c_str()); @@ -509,7 +510,7 @@ void LPEMeasureLine::saveDefault() { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setString("/live_effects/measure-line/fontselector", (Glib::ustring)fontselector.param_getSVGValue()); + prefs->setString("/live_effects/measure-line/fontbutton", (Glib::ustring)fontbutton.param_getSVGValue()); prefs->setDouble("/live_effects/measure-line/scale", scale); prefs->setInt("/live_effects/measure-line/precision", precision); prefs->setDouble("/live_effects/measure-line/offset_right_left", offset_right_left); diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index 67d27408a..15831e231 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -12,7 +12,7 @@ #include "live_effects/effect.h" #include "live_effects/parameter/enum.h" -#include "live_effects/parameter/font.h" +#include "live_effects/parameter/fontbutton.h" #include "live_effects/parameter/text.h" #include "live_effects/parameter/unit.h" #include "live_effects/parameter/bool.h" @@ -47,8 +47,7 @@ public: void saveDefault(); virtual Gtk::Widget *newWidget(); private: - FontParam fontselector; - Inkscape::FontLister *fontlister; + FontButtonParam fontbutton; EnumParam orientation; OriginalPathParam origin; ScalarParam curve_linked; diff --git a/src/live_effects/parameter/Makefile_insert b/src/live_effects/parameter/Makefile_insert index bd1c5b600..d9cd5b3c1 100644 --- a/src/live_effects/parameter/Makefile_insert +++ b/src/live_effects/parameter/Makefile_insert @@ -11,6 +11,8 @@ ink_common_sources += \ live_effects/parameter/random.h \ live_effects/parameter/point.cpp \ live_effects/parameter/point.h \ + live_effects/parameter/fontbutton.cpp \ + live_effects/parameter/fontbutton.h \ live_effects/parameter/enum.h \ live_effects/parameter/path-reference.cpp \ live_effects/parameter/path-reference.h \ diff --git a/src/live_effects/parameter/font.cpp b/src/live_effects/parameter/font.cpp deleted file mode 100644 index 8f89ee5c4..000000000 --- a/src/live_effects/parameter/font.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Authors: - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - - -#include "ui/widget/registered-widget.h" -#include "live_effects/parameter/font.h" -#include "live_effects/effect.h" -#include "ui/widget/font-selector.h" -#include "svg/svg.h" -#include "svg/stringstream.h" -#include "verbs.h" - -#include - -namespace Inkscape { - -namespace LivePathEffect { - -FontParam::FontParam( const Glib::ustring& label, const Glib::ustring& tip, - const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, - Effect* effect, const Glib::ustring default_value ) - : Parameter(label, tip, key, wr, effect), - value(default_value), - defvalue(default_value) -{ -} - -void -FontParam::param_set_default() -{ - param_setValue(defvalue); -} -void -FontParam::param_update_default(const Glib::ustring default_value){ - defvalue = default_value; -} - -Glib::ustring -FontParam::param_readFontSpec(const gchar * strvalue) -{ - Glib::ustring result; - gchar ** strarray = g_strsplit(strvalue, " @ ", 2); - double fontsize; - if (strarray[1]) { - unsigned int success = sp_svg_number_read_d(strarray[1], &fontsize); - if (success == 1) { - result = (Glib::ustring)strarray[0]; - g_strfreev (strarray); - return result; - } - } - g_strfreev (strarray); - return result; -} - -double -FontParam::param_readFontSize(const gchar * strvalue) -{ - gchar ** strarray = g_strsplit(strvalue, " @ ", 2); - double fontsize = 0; - if (strarray[1]) { - unsigned int success = sp_svg_number_read_d(strarray[1], &fontsize); - if (success == 1) { - g_strfreev (strarray); - return fontsize; - } - } - g_strfreev (strarray); - return fontsize; -} - -bool -FontParam::param_readSVGValue(const gchar * strvalue) -{ - double fontsize = param_readFontSize(strvalue); - Glib::ustring fontspec = param_readFontSpec(strvalue); - Inkscape::SVGOStringStream os; - os << fontspec << " @ " << fontsize; - param_setValue((Glib::ustring)os.str()); - return true; -} - -gchar * -FontParam::param_getSVGValue() const -{ - return g_strdup(value.c_str()); -} - -Gtk::Widget * -FontParam::param_newWidget() -{ - Inkscape::UI::Widget::RegisteredFontSelector * fontselectorwdg = Gtk::manage( - new Inkscape::UI::Widget::RegisteredFontSelector( param_label, - param_tooltip, - param_key, - *param_wr, - param_effect->getRepr(), - param_effect->getSPDoc() ) ); - double fontsize = param_readFontSize(param_getSVGValue()); - Glib::ustring fontspec = param_readFontSpec(param_getSVGValue()); - fontselectorwdg->setValue( fontspec, fontsize ); - fontselectorwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change font selector parameter")); - param_effect->upd_params = false; - return dynamic_cast (fontselectorwdg); -} - -void -FontParam::param_setValue(const Glib::ustring newvalue) -{ - value = newvalue; -} - -} /* namespace LivePathEffect */ - -} /* namespace Inkscape */ - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/live_effects/parameter/font.h b/src/live_effects/parameter/font.h deleted file mode 100644 index 3909ea424..000000000 --- a/src/live_effects/parameter/font.h +++ /dev/null @@ -1,78 +0,0 @@ -#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_FONT_H -#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_FONT_H - -/* - * Inkscape::LivePathEffectParameters - * - * Authors: - * Released under GNU GPL, read the file 'COPYING' for more information - */ -#include -#include -#include "live_effects/parameter/parameter.h" - -namespace Inkscape { - -namespace LivePathEffect { - -class FontParam : public Parameter { -public: - FontParam( const Glib::ustring& label, - const Glib::ustring& tip, - const Glib::ustring& key, - Inkscape::UI::Widget::Registry* wr, - Effect* effect, - const Glib::ustring default_value = ""); - virtual ~FontParam() {} - - virtual Gtk::Widget * param_newWidget(); - virtual bool param_readSVGValue(const gchar * strvalue); - double param_readFontSize(const gchar * strvalue); - void param_update_default(const Glib::ustring defvalue); - Glib::ustring param_readFontSpec(const gchar * strvalue); - virtual gchar * param_getSVGValue() const; - - void param_setValue(const Glib::ustring newvalue); - - virtual void param_set_default(); - - const Glib::ustring get_value() const { return defvalue; }; - -private: - FontParam(const FontParam&); - FontParam& operator=(const FontParam&); - Glib::ustring value; - Glib::ustring defvalue; - -}; - -/* - * This parameter does not display a widget in the LPE dialog; LPEs can use it to display on-canvas - * text that should not be settable by the user. Note that since no widget is provided, the - * parameter must be initialized differently than usual (only with a pointer to the parent effect; - * no label, no tooltip, etc.). - */ -class FontParamInternal : public FontParam { -public: - FontParamInternal(Effect* effect) : - FontParam("", "", "", NULL, effect) {} - - virtual Gtk::Widget * param_newWidget() { return NULL; } -}; - -} //namespace LivePathEffect - -} //namespace Inkscape - -#endif - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/live_effects/parameter/fontbutton.cpp b/src/live_effects/parameter/fontbutton.cpp new file mode 100644 index 000000000..ff8ab76a0 --- /dev/null +++ b/src/live_effects/parameter/fontbutton.cpp @@ -0,0 +1,92 @@ +/* + * Authors: + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + + +#include "ui/widget/registered-widget.h" +#include "live_effects/parameter/fontbutton.h" +#include "live_effects/effect.h" +#include "ui/widget/font-button.h" +#include "svg/svg.h" +#include "svg/stringstream.h" +#include "verbs.h" + +#include + +namespace Inkscape { + +namespace LivePathEffect { + +FontButtonParam::FontButtonParam( const Glib::ustring& label, const Glib::ustring& tip, + const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, + Effect* effect, const Glib::ustring default_value ) + : Parameter(label, tip, key, wr, effect), + value(default_value), + defvalue(default_value) +{ +} + +void +FontButtonParam::param_set_default() +{ + param_setValue(defvalue); +} +void +FontButtonParam::param_update_default(const Glib::ustring default_value){ + defvalue = default_value; +} + +bool +FontButtonParam::param_readSVGValue(const gchar * strvalue) +{ + Inkscape::SVGOStringStream os; + os << strvalue; + param_setValue((Glib::ustring)os.str()); + return true; +} + +gchar * +FontButtonParam::param_getSVGValue() const +{ + return g_strdup(value.c_str()); +} + +Gtk::Widget * +FontButtonParam::param_newWidget() +{ + Inkscape::UI::Widget::RegisteredFontButton * fontbuttonwdg = Gtk::manage( + new Inkscape::UI::Widget::RegisteredFontButton( param_label, + param_tooltip, + param_key, + *param_wr, + param_effect->getRepr(), + param_effect->getSPDoc() ) ); + Glib::ustring fontspec = param_getSVGValue(); + fontbuttonwdg->setValue( fontspec); + fontbuttonwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change font button parameter")); + param_effect->upd_params = false; + return dynamic_cast (fontbuttonwdg); +} + +void +FontButtonParam::param_setValue(const Glib::ustring newvalue) +{ + value = newvalue; +} + +} /* namespace LivePathEffect */ + +} /* namespace Inkscape */ + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/live_effects/parameter/fontbutton.h b/src/live_effects/parameter/fontbutton.h new file mode 100644 index 000000000..387ad130b --- /dev/null +++ b/src/live_effects/parameter/fontbutton.h @@ -0,0 +1,62 @@ +#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_FONT_H +#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_FONT_H + +/* + * Inkscape::LivePathEffectParameters + * + * Authors: + * Released under GNU GPL, read the file 'COPYING' for more information + */ +#include +#include +#include "live_effects/parameter/parameter.h" + +namespace Inkscape { + +namespace LivePathEffect { + +class FontButtonParam : public Parameter { +public: + FontButtonParam( const Glib::ustring& label, + const Glib::ustring& tip, + const Glib::ustring& key, + Inkscape::UI::Widget::Registry* wr, + Effect* effect, + const Glib::ustring default_value = ""); + virtual ~FontButtonParam() {} + + virtual Gtk::Widget * param_newWidget(); + virtual bool param_readSVGValue(const gchar * strvalue); + void param_update_default(const Glib::ustring defvalue); + virtual gchar * param_getSVGValue() const; + + void param_setValue(const Glib::ustring newvalue); + + virtual void param_set_default(); + + const Glib::ustring get_value() const { return defvalue; }; + +private: + FontButtonParam(const FontButtonParam&); + FontButtonParam& operator=(const FontButtonParam&); + Glib::ustring value; + Glib::ustring defvalue; + +}; + +} //namespace LivePathEffect + +} //namespace Inkscape + +#endif + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : -- cgit v1.2.3 From f391d1cb5c644cd325f64a88d6d3a9da73fdb9de Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 30 Jul 2016 02:50:36 +0200 Subject: Fixes positions of labels (bzr r15017.1.14) --- src/live_effects/lpe-measure-line.cpp | 113 +++++++++++++++++++++++----------- src/live_effects/lpe-measure-line.h | 2 +- 2 files changed, 77 insertions(+), 38 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 5df3d499e..d0252aea9 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -215,6 +215,9 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } s[Geom::X] = xpos; e[Geom::X] = xpos; + if (s[Geom::Y] > e[Geom::Y]) { + swap(s,e); + } } if(*om_it == OM_HORIZONTAL) { Coord ypos = std::max(s[Geom::Y],e[Geom::Y]); @@ -223,6 +226,9 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } s[Geom::Y] = ypos; e[Geom::Y] = ypos; + if (s[Geom::X] < e[Geom::X]) { + swap(s,e); + } } Geom::Ray ray(s,e); Geom::Coord angle = ray.angle(); @@ -250,6 +256,9 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } s[Geom::X] = xpos; e[Geom::X] = xpos; + if (s[Geom::Y] > e[Geom::Y]) { + swap(s,e); + } } if(*om_it == OM_HORIZONTAL) { Coord ypos = std::max(s[Geom::Y],e[Geom::Y]); @@ -258,6 +267,9 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } s[Geom::Y] = ypos; e[Geom::Y] = ypos; + if (s[Geom::X] < e[Geom::X]) { + swap(s,e); + } } } double length = Geom::distance(s, e) * scale; @@ -406,28 +418,55 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } } -void LPEMeasureLine::doOnRemove (SPLPEItem const* /*lpeitem*/) +void LPEMeasureLine::doOnRemove (SPLPEItem const* lpeitem) { -// if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { -// if (horizontal_text) { -// SPObject * text_obj = desktop->currentLayer()->get_child_by_repr(horizontal_text); -// if (text_obj) { -// text_obj->deleteObject(); -// } -// } -// if (vertical_text) { -// SPObject * text_obj = desktop->currentLayer()->get_child_by_repr(vertical_text); -// if (text_obj) { -// text_obj->deleteObject(); -// } -// } -// if (parallel_text) { -// SPObject * text_obj = desktop->currentLayer()->get_child_by_repr(parallel_text); -// if (text_obj) { -// text_obj->deleteObject(); -// } -// } -// } + if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { + SPLPEItem * splpeitem = const_cast(lpeitem); + std::vector orientations; + std::vector orientations_remove; + if ( orientation == OM_HORIZONTAL || + orientation == OM_PARALLEL_VERTICAL_HORIZONTAL || + orientation == OM_PARALLEL_HORIZONTAL || + orientation == OM_VERTICAL_HORIZONTAL) + { + orientations.push_back(OM_HORIZONTAL); + } + if ( orientation == OM_VERTICAL || + orientation == OM_PARALLEL_VERTICAL_HORIZONTAL || + orientation == OM_PARALLEL_VERTICAL || + orientation == OM_VERTICAL_HORIZONTAL) + { + orientations.push_back(OM_VERTICAL); + } + if ( orientation == OM_PARALLEL || + orientation == OM_PARALLEL_VERTICAL_HORIZONTAL || + orientation == OM_PARALLEL_VERTICAL || + orientation == OM_PARALLEL_HORIZONTAL) + { + orientations.push_back(OM_PARALLEL); + } + for (std::vector::const_iterator om_it = orientations.begin(); om_it != orientations.end(); ++om_it) { + Glib::ustring orientation_str; + Inkscape::XML::Node *rtext = NULL; + if (*om_it == OM_VERTICAL) { + orientation_str = "vertical"; + } + if (*om_it == OM_HORIZONTAL) { + orientation_str = "horizontal"; + } + if (*om_it == OM_PARALLEL) { + orientation_str = "parallel"; + } + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_DINnumber_" + orientation_str).c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + Inkscape::XML::Node *rtspan = NULL; + if (elemref = SVGElemRef->getObject()) { + elemref->deleteObject(); + } + } + } } Gtk::Widget *LPEMeasureLine::newWidget() @@ -483,22 +522,22 @@ LPEMeasureLine::doEffect_path(Geom::PathVector const &path_in) angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); if (angle < 0) angle += 2*M_PI; e = e - Point::polar(angle, gap_end); - if(orientation == OM_VERTICAL) { - Coord xpos = std::max(s[Geom::X],e[Geom::X]); - if (reverse) { - xpos = std::min(s[Geom::X],e[Geom::X]); - } - s[Geom::X] = xpos; - e[Geom::X] = xpos; - } - if(orientation == OM_HORIZONTAL) { - Coord ypos = std::max(s[Geom::Y],e[Geom::Y]); - if (reverse) { - ypos = std::min(s[Geom::Y],e[Geom::Y]); - } - s[Geom::Y] = ypos; - e[Geom::Y] = ypos; - } +// if(orientation == OM_VERTICAL) { +// Coord xpos = std::max(s[Geom::X],e[Geom::X]); +// if (reverse) { +// xpos = std::min(s[Geom::X],e[Geom::X]); +// } +// s[Geom::X] = xpos; +// e[Geom::X] = xpos; +// } +// if(orientation == OM_HORIZONTAL) { +// Coord ypos = std::max(s[Geom::Y],e[Geom::Y]); +// if (reverse) { +// ypos = std::min(s[Geom::Y],e[Geom::Y]); +// } +// s[Geom::Y] = ypos; +// e[Geom::Y] = ypos; +// } path.start( s ); path.appendNew( e ); Geom::PathVector output; diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index 15831e231..05f9b2f73 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -42,7 +42,7 @@ public: virtual ~LPEMeasureLine(); virtual void doBeforeEffect (SPLPEItem const* lpeitem); virtual void doOnApply(SPLPEItem const* lpeitem); - virtual void doOnRemove (SPLPEItem const* /*lpeitem*/); + virtual void doOnRemove (SPLPEItem const* lpeitem); virtual Geom::PathVector doEffect_path(Geom::PathVector const &path_in); void saveDefault(); virtual Gtk::Widget *newWidget(); -- cgit v1.2.3 From 7f16afbb515eceed9c63afacec73cd528a662327 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 30 Jul 2016 19:04:34 +0200 Subject: Full rewrite on working mode now no linked paths necesary (bzr r15017.1.15) --- src/live_effects/effect.cpp | 4 +- src/live_effects/effect.h | 2 +- src/live_effects/lpe-measure-line.cpp | 528 +++++++++++-------------------- src/live_effects/lpe-measure-line.h | 9 +- src/live_effects/parameter/parameter.cpp | 43 +-- src/live_effects/parameter/parameter.h | 2 - 6 files changed, 198 insertions(+), 390 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index a62e8b62b..7efc1a711 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -454,7 +454,9 @@ void Effect::doAfterEffect (SPLPEItem const* /*lpeitem*/) void Effect::doOnRemove (SPLPEItem const* /*lpeitem*/) { } - +void Effect::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) +{ +} //secret impl methods (shhhh!) void Effect::doOnApply_impl(SPLPEItem const* lpeitem) { diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index e0a7cbe6b..f54624302 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -66,7 +66,7 @@ public: virtual void doAfterEffect (SPLPEItem const* lpeitem); virtual void doOnRemove (SPLPEItem const* lpeitem); - + virtual void doOnVisibilityToggled(SPLPEItem const* lpeitem); void writeParamsToSVG(); virtual void acceptParamPath (SPPath const* param_path); diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index d0252aea9..6d58e2b7d 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -39,11 +39,7 @@ namespace LivePathEffect { static const Util::EnumData OrientationMethodData[] = { { OM_HORIZONTAL, N_("Horizontal"), "horizontal" }, { OM_VERTICAL, N_("Vertical"), "vertical" }, - { OM_PARALLEL, N_("Parallel"), "parallel" }, - { OM_PARALLEL_VERTICAL, N_("Parallel and vertical,"), "parallel_vertical" }, - { OM_PARALLEL_HORIZONTAL, N_("Parallel and horizontal"), "parallel_horizontal" }, - { OM_VERTICAL_HORIZONTAL, N_("Vertical and horizontal"), "vertical_horizontal" }, - { OM_PARALLEL_VERTICAL_HORIZONTAL, N_("Parallel, vertical and horizontal"), "parallel_vertical_horizontal" } + { OM_PARALLEL, N_("Parallel"), "parallel" } }; static const Util::EnumDataConverter OMConverter(OrientationMethodData, OM_END); @@ -51,9 +47,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : Effect(lpeobject), fontbutton(_("Font*"), _("Font Selector"), "fontbutton", &wr, this), orientation(_("Orientation"), _("Orientation method"), "orientation", OMConverter, &wr, this, OM_PARALLEL, false), - origin(_("Optional Origin"), _("Optional origin"), "origin", &wr, this), - curve_linked(_("Curve on optional origin"), _("Curve on optional origin, set 0 to start/end"), "curve_linked", &wr, this, 1), - origin_offset(_("Optional origin offset*"), _("Optional origin offset"), "origin_offset", &wr, this, 5), + curve_linked(_("Curve on origin"), _("Curve on origin, set 0 to start/end"), "curve_linked", &wr, this, 1), scale(_("Scale*"), _("Scaling factor"), "scale", &wr, this, 1.0), precision(_("Precision*"), _("Precision"), "precision", &wr, this, 2), offset_right_left(_("Offset right left*"), _("Offset right left"), "offset_right_left", &wr, this, 0), @@ -68,9 +62,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : { registerParameter(&fontbutton); registerParameter(&orientation); - registerParameter(&origin); registerParameter(&curve_linked); - registerParameter(&origin_offset); registerParameter(&scale); registerParameter(&precision); registerParameter(&offset_right_left); @@ -88,7 +80,6 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : precision.param_update_default(prefs->getInt("/live_effects/measure-line/precision", 2)); offset_right_left.param_update_default(prefs->getDouble("/live_effects/measure-line/offset_right_left", 0.0)); offset_top_bottom.param_update_default(prefs->getDouble("/live_effects/measure-line/offset_top_bottom", 5.0)); - origin_offset.param_update_default(prefs->getDouble("/live_effects/measure-line/origin_offset", 5.0)); unit.param_update_default(prefs->getString("/live_effects/measure-line/unit")); reverse.param_update_default(prefs->getBool("/live_effects/measure-line/reverse")); color_as_line.param_update_default(prefs->getBool("/live_effects/measure-line/color_as_line")); @@ -98,7 +89,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : precision.param_set_increments(1, 1); precision.param_set_digits(0); precision.param_make_integer(true); - curve_linked.param_set_range(1, 999); + curve_linked.param_set_range(0, 999); curve_linked.param_set_increments(1, 1); curve_linked.param_set_digits(0); curve_linked.param_make_integer(true); @@ -109,9 +100,6 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : offset_top_bottom.param_set_range(-999999.0, 999999.0); offset_top_bottom.param_set_increments(1, 1); offset_top_bottom.param_set_digits(2); - origin_offset.param_set_range(-999999.0, 999999.0); - origin_offset.param_set_increments(1, 1); - origin_offset.param_set_digits(2); gap_start.param_set_range(-999999.0, 999999.0); gap_start.param_set_increments(1, 1); gap_start.param_set_digits(2); @@ -120,8 +108,6 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : gap_end.param_set_digits(2); } -bool LPEMeasureLine::alerts_off = false; - LPEMeasureLine::~LPEMeasureLine() {} void @@ -131,16 +117,24 @@ LPEMeasureLine::doOnApply(SPLPEItem const* lpeitem) g_warning("LPE measure line can only be applied to shapes (not groups)."); SPLPEItem * item = const_cast(lpeitem); item->removeCurrentPathEffect(false); - } else { - if(!alerts_off) { - char *msg = _("The \"measure line\" path effect could update original path on the object you are applying it to if link it to other path. If this is not what you want, click Cancel."); - Gtk::MessageDialog dialog(msg, false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_OK_CANCEL, true); - gint response = dialog.run(); - alerts_off = true; - if(response == GTK_RESPONSE_CANCEL) { - SPLPEItem* item = const_cast(lpeitem); - item->removeCurrentPathEffect(false); - return; + } +} + +void +LPEMeasureLine::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) +{ + if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)this->getRepr()->attribute("id") + (Glib::ustring)"_text").c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + Inkscape::XML::Node *rtext = NULL; + if (elemref = SVGElemRef->getObject()) { + rtext = elemref->getRepr(); + if (!this->isVisible()) { + rtext->setAttribute("style", "display:none"); + } else { + rtext->setAttribute("style", NULL); } } } @@ -154,266 +148,166 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) if (sp_path) { Geom::PathVector pathvector = sp_path->get_original_curve()->get_pathvector(); if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { - Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); - std::vector orientations; - std::vector orientations_remove; - if ( orientation == OM_HORIZONTAL || - orientation == OM_PARALLEL_VERTICAL_HORIZONTAL || - orientation == OM_PARALLEL_HORIZONTAL || - orientation == OM_VERTICAL_HORIZONTAL) - { - orientations.push_back(OM_HORIZONTAL); - } else { - orientations_remove.push_back(OM_HORIZONTAL); - } - if ( orientation == OM_VERTICAL || - orientation == OM_PARALLEL_VERTICAL_HORIZONTAL || - orientation == OM_PARALLEL_VERTICAL || - orientation == OM_VERTICAL_HORIZONTAL) - { - orientations.push_back(OM_VERTICAL); - } else { - orientations_remove.push_back(OM_VERTICAL); + size_t ncurves = pathvector.curveCount(); + curve_linked.param_set_range(0, ncurves); + Geom::Point s = pathvector.initialPoint(); + Geom::Point e = pathvector.finalPoint(); + if (curve_linked) { //0 start-end nodes + s = pathvector.pointAt(curve_linked -1); + e = pathvector.pointAt(curve_linked); } - if ( orientation == OM_PARALLEL || - orientation == OM_PARALLEL_VERTICAL_HORIZONTAL || - orientation == OM_PARALLEL_VERTICAL || - orientation == OM_PARALLEL_HORIZONTAL) - { - orientations.push_back(OM_PARALLEL); - } else { - orientations_remove.push_back(OM_PARALLEL); - } - for (std::vector::const_iterator om_it = orientations.begin(); om_it != orientations.end(); ++om_it) { - Geom::Point s = pathvector.initialPoint(); - Geom::Point e = pathvector.finalPoint(); - Glib::ustring orientation_str; - Inkscape::XML::Node *rtext = NULL; - if (*om_it == OM_VERTICAL) { - orientation_str = "vertical"; - } - if (*om_it == OM_HORIZONTAL) { - orientation_str = "horizontal"; + Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); + Glib::ustring orientation_str; + Inkscape::XML::Node *rtext = NULL; + if (orientation == OM_VERTICAL) { + orientation_str = "vertical"; + Coord xpos = std::max(s[Geom::X],e[Geom::X]); + if (reverse) { + xpos = std::min(s[Geom::X],e[Geom::X]); } - if (*om_it == OM_PARALLEL) { - orientation_str = "parallel"; + s[Geom::X] = xpos; + e[Geom::X] = xpos; + if (s[Geom::Y] > e[Geom::Y]) { + swap(s,e); } - if (origin.linksToPath() && origin.getObject() && !origin.get_pathvector().empty()) { - pathvector = origin.get_pathvector(); - size_t ncurves = pathvector.curveCount(); - curve_linked.param_set_range(1, ncurves); - if(previous_ncurves != ncurves) { - this->upd_params = true; - previous_ncurves = ncurves; - } - s = pathvector.pointAt(curve_linked -1); - e = pathvector.pointAt(curve_linked); - if(*om_it == OM_VERTICAL) { - Coord xpos = std::max(s[Geom::X],e[Geom::X]); - if (reverse) { - xpos = std::min(s[Geom::X],e[Geom::X]); - } - s[Geom::X] = xpos; - e[Geom::X] = xpos; - if (s[Geom::Y] > e[Geom::Y]) { - swap(s,e); - } - } - if(*om_it == OM_HORIZONTAL) { - Coord ypos = std::max(s[Geom::Y],e[Geom::Y]); - if (reverse) { - ypos = std::min(s[Geom::Y],e[Geom::Y]); - } - s[Geom::Y] = ypos; - e[Geom::Y] = ypos; - if (s[Geom::X] < e[Geom::X]) { - swap(s,e); - } - } - Geom::Ray ray(s,e); - Geom::Coord angle = ray.angle(); - if (reverse) { - angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); - if (angle < 0) angle += 2*M_PI; - } - Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); - if (angle_cross < 0) angle_cross += 2*M_PI; - s = s - Point::polar(angle_cross, origin_offset); - e = e - Point::polar(angle_cross, origin_offset); - Geom::Path path; - path.start( s ); - path.appendNew( e ); - Geom::PathVector line_upd; - line_upd.push_back(path); - Inkscape::XML::Node *line = SP_OBJECT(sp_path)->getRepr(); - gchar *str = sp_svg_write_path(line_upd); - line->setAttribute("inkscape:original-d", str); - } else { - if(*om_it == OM_VERTICAL) { - Coord xpos = std::max(s[Geom::X],e[Geom::X]); - if (reverse) { - xpos = std::min(s[Geom::X],e[Geom::X]); - } - s[Geom::X] = xpos; - e[Geom::X] = xpos; - if (s[Geom::Y] > e[Geom::Y]) { - swap(s,e); - } - } - if(*om_it == OM_HORIZONTAL) { - Coord ypos = std::max(s[Geom::Y],e[Geom::Y]); - if (reverse) { - ypos = std::min(s[Geom::Y],e[Geom::Y]); - } - s[Geom::Y] = ypos; - e[Geom::Y] = ypos; - if (s[Geom::X] < e[Geom::X]) { - swap(s,e); - } - } - } - double length = Geom::distance(s, e) * scale; - Geom::Point pos = Geom::middle_point(s,e); - Geom::Ray ray(s,e); - Geom::Coord angle = ray.angle(); - doc_unit = Inkscape::Util::unit_table.getUnit(desktop->doc()->getRoot()->height.unit)->abbr; + } + if (orientation == OM_HORIZONTAL) { + orientation_str = "horizontal"; + Coord ypos = std::max(s[Geom::Y],e[Geom::Y]); if (reverse) { - angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); - if (angle < 0) angle += 2*M_PI; + ypos = std::min(s[Geom::Y],e[Geom::Y]); } - Geom::Point newpos = pos - Point::polar(angle, offset_right_left); - Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); - if (angle_cross < 0) angle_cross += 2*M_PI; - newpos = newpos - Point::polar(angle_cross, offset_top_bottom); - Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_DINnumber_" + orientation_str).c_str()); - Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); - SVGElemRef->attach(SVGElem_uri); - SPObject *elemref = NULL; - Inkscape::XML::Node *rtspan = NULL; - if (elemref = SVGElemRef->getObject()) { - rtext = elemref->getRepr(); - sp_repr_set_svg_double(rtext, "x", newpos[Geom::X]); - sp_repr_set_svg_double(rtext, "y", newpos[Geom::Y]); - } else { - rtext = xml_doc->createElement("svg:text"); - rtext->setAttribute("xml:space", "preserve"); - rtext->setAttribute("sodipodi:insensitive", "true"); - rtext->setAttribute("id", ((Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_DINnumber_" + orientation_str).c_str()); - /* Set style */ - sp_repr_set_svg_double(rtext, "x", newpos[Geom::X]); - sp_repr_set_svg_double(rtext, "y", newpos[Geom::Y]); - /* Create */ - rtspan = xml_doc->createElement("svg:tspan"); - rtspan->setAttribute("sodipodi:role", "line"); + s[Geom::Y] = ypos; + e[Geom::Y] = ypos; + if (s[Geom::X] < e[Geom::X]) { + swap(s,e); } - SPCSSAttr *css = sp_repr_css_attr_new(); - Pango::FontDescription fontdesc((Glib::ustring)fontbutton.param_getSVGValue()); - double fontsize = fontdesc.get_size()/Pango::SCALE; - Inkscape::FontLister *fontlister = Inkscape::FontLister::get_instance(); - fontlister->fill_css( css, (Glib::ustring)fontbutton.param_getSVGValue() ); - std::stringstream font_size; - font_size.imbue(std::locale::classic()); - font_size << fontsize << "pt"; - sp_repr_css_set_property (css, "font-size", font_size.str().c_str()); - sp_repr_css_set_property (css, "line-height", "125%"); - sp_repr_css_set_property (css, "letter-spacing", "0"); - sp_repr_css_set_property (css, "word-spacing", "0"); - sp_repr_css_set_property (css, "text-align", "center"); - sp_repr_css_set_property (css, "text-anchor", "middle"); - if (color_as_line) { - if (lpeitem->style) { - if (lpeitem->style->stroke.isPaintserver()) { - SPPaintServer * server = lpeitem->style->getStrokePaintServer(); - if (server) { - Glib::ustring str; - str += "url(#"; - str += server->getId(); - str += ")"; - sp_repr_css_set_property (css, "fill", str.c_str()); - } - } else if (lpeitem->style->stroke.isColor()) { - gchar c[64]; - sp_svg_write_color (c, sizeof(c), lpeitem->style->stroke.value.color.toRGBA32(SP_SCALE24_TO_FLOAT(lpeitem->style->stroke_opacity.value))); - sp_repr_css_set_property (css, "fill", c); - } else { - sp_repr_css_set_property (css, "fill", "#000000"); + } + if (orientation == OM_PARALLEL) { + orientation_str = "parallel"; + } + double length = Geom::distance(s, e) * scale; + Geom::Point pos = Geom::middle_point(s,e); + Geom::Ray ray(s,e); + Geom::Coord angle = ray.angle(); + doc_unit = Inkscape::Util::unit_table.getUnit(desktop->doc()->getRoot()->height.unit)->abbr; + if (reverse) { + angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); + if (angle < 0) angle += 2*M_PI; + } + Geom::Point newpos = pos - Point::polar(angle, offset_right_left); + Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); + if (angle_cross < 0) angle_cross += 2*M_PI; + newpos = newpos - Point::polar(angle_cross, offset_top_bottom); + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)this->getRepr()->attribute("id") + (Glib::ustring)"_text").c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + Inkscape::XML::Node *rtspan = NULL; + if (elemref = SVGElemRef->getObject()) { + rtext = elemref->getRepr(); + sp_repr_set_svg_double(rtext, "x", newpos[Geom::X]); + sp_repr_set_svg_double(rtext, "y", newpos[Geom::Y]); + } else { + rtext = xml_doc->createElement("svg:text"); + rtext->setAttribute("xml:space", "preserve"); + rtext->setAttribute("sodipodi:insensitive", "true"); + rtext->setAttribute("id", ((Glib::ustring)this->getRepr()->attribute("id") + (Glib::ustring)"_text").c_str()); + /* Set style */ + sp_repr_set_svg_double(rtext, "x", newpos[Geom::X]); + sp_repr_set_svg_double(rtext, "y", newpos[Geom::Y]); + /* Create */ + rtspan = xml_doc->createElement("svg:tspan"); + rtspan->setAttribute("sodipodi:role", "line"); + } + SPCSSAttr *css = sp_repr_css_attr_new(); + Pango::FontDescription fontdesc((Glib::ustring)fontbutton.param_getSVGValue()); + double fontsize = fontdesc.get_size()/Pango::SCALE; + Inkscape::FontLister *fontlister = Inkscape::FontLister::get_instance(); + fontlister->fill_css( css, (Glib::ustring)fontbutton.param_getSVGValue() ); + std::stringstream font_size; + font_size.imbue(std::locale::classic()); + font_size << fontsize << "pt"; + sp_repr_css_set_property (css, "font-size", font_size.str().c_str()); + sp_repr_css_set_property (css, "line-height", "125%"); + sp_repr_css_set_property (css, "letter-spacing", "0"); + sp_repr_css_set_property (css, "word-spacing", "0"); + sp_repr_css_set_property (css, "text-align", "center"); + sp_repr_css_set_property (css, "text-anchor", "middle"); + if (color_as_line) { + if (lpeitem->style) { + if (lpeitem->style->stroke.isPaintserver()) { + SPPaintServer * server = lpeitem->style->getStrokePaintServer(); + if (server) { + Glib::ustring str; + str += "url(#"; + str += server->getId(); + str += ")"; + sp_repr_css_set_property (css, "fill", str.c_str()); } + } else if (lpeitem->style->stroke.isColor()) { + gchar c[64]; + sp_svg_write_color (c, sizeof(c), lpeitem->style->stroke.value.color.toRGBA32(SP_SCALE24_TO_FLOAT(lpeitem->style->stroke_opacity.value))); + sp_repr_css_set_property (css, "fill", c); } else { - sp_repr_css_unset_property (css, "#000000"); + sp_repr_css_set_property (css, "fill", "#000000"); } } else { - sp_repr_css_set_property (css, "fill", "#000000"); - } - sp_repr_css_set_property (css, "fill-opacity", "1"); - sp_repr_css_set_property (css, "stroke", "none"); - Glib::ustring css_str; - sp_repr_css_write_string(css,css_str); - if (!rtspan) { - rtspan = rtext->firstChild(); - } - rtspan->setAttribute("style", css_str.c_str()); - sp_repr_css_attr_unref (css); - if (!elemref) { - rtext->addChild(rtspan, NULL); - Inkscape::GC::release(rtspan); - } - /* Create TEXT */ - if (!scale_insensitive) { - Geom::Affine affinetransform = i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(desktop->doc()->getRoot())); - length *= (affinetransform.expansionX() + affinetransform.expansionY()) / 2.0; - } - length = Inkscape::Util::Quantity::convert(length, doc_unit.c_str(), unit.get_abbreviation()); - std::stringstream length_str; - length_str.precision(precision); - length_str.setf(std::ios::fixed, std::ios::floatfield); - if (local_locale) { - length_str.imbue(std::locale("")); - } else { - length_str.imbue(std::locale::classic()); - } - length_str << std::fixed << length; - length_str << unit.get_abbreviation(); - Inkscape::XML::Node *rstring = NULL; - if (!elemref) { - rstring = xml_doc->createTextNode(length_str.str().c_str()); - rtspan->addChild(rstring, NULL); - Inkscape::GC::release(rstring); - } else { - rstring = rtspan->firstChild(); - rstring->setContent(length_str.str().c_str()); + sp_repr_css_unset_property (css, "#000000"); } - SPObject * text_obj = NULL; - if (!elemref) { - text_obj = SP_OBJECT(desktop->currentLayer()->appendChildRepr(rtext)); - Inkscape::GC::release(rtext); - } else { - text_obj = desktop->currentLayer()->get_child_by_repr(rtext); - } - Geom::Affine affine = Geom::Affine(Geom::Translate(newpos).inverse()); - affine *= Geom::Rotate(angle); - affine *= Geom::Translate(newpos); - SP_ITEM(text_obj)->transform = affine * i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(desktop->doc()->getRoot())); - text_obj->updateRepr(); + } else { + sp_repr_css_set_property (css, "fill", "#000000"); } - for (std::vector::const_iterator omdel_it = orientations_remove.begin(); omdel_it != orientations_remove.end(); ++omdel_it) { - Glib::ustring orientation_str; - if (*omdel_it == OM_VERTICAL) { - orientation_str = "vertical"; - } - if (*omdel_it == OM_HORIZONTAL) { - orientation_str = "horizontal"; - } - if (*omdel_it == OM_PARALLEL) { - orientation_str = "parallel"; - } - Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_DINnumber_" + orientation_str).c_str()); - Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); - SVGElemRef->attach(SVGElem_uri); - SPObject *elemref = NULL; - if (elemref = SVGElemRef->getObject()) { - elemref->deleteObject(); - } + sp_repr_css_set_property (css, "fill-opacity", "1"); + sp_repr_css_set_property (css, "stroke", "none"); + Glib::ustring css_str; + sp_repr_css_write_string(css,css_str); + if (!rtspan) { + rtspan = rtext->firstChild(); + } + rtspan->setAttribute("style", css_str.c_str()); + sp_repr_css_attr_unref (css); + if (!elemref) { + rtext->addChild(rtspan, NULL); + Inkscape::GC::release(rtspan); + } + /* Create TEXT */ + if (!scale_insensitive) { + Geom::Affine affinetransform = i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(desktop->doc()->getRoot())); + length *= (affinetransform.expansionX() + affinetransform.expansionY()) / 2.0; + } + length = Inkscape::Util::Quantity::convert(length, doc_unit.c_str(), unit.get_abbreviation()); + std::stringstream length_str; + length_str.precision(precision); + length_str.setf(std::ios::fixed, std::ios::floatfield); + if (local_locale) { + length_str.imbue(std::locale("")); + } else { + length_str.imbue(std::locale::classic()); } + length_str << std::fixed << length; + length_str << unit.get_abbreviation(); + Inkscape::XML::Node *rstring = NULL; + if (!elemref) { + rstring = xml_doc->createTextNode(length_str.str().c_str()); + rtspan->addChild(rstring, NULL); + Inkscape::GC::release(rstring); + } else { + rstring = rtspan->firstChild(); + rstring->setContent(length_str.str().c_str()); + } + SPObject * text_obj = NULL; + if (!elemref) { + text_obj = SP_OBJECT(desktop->currentLayer()->appendChildRepr(rtext)); + Inkscape::GC::release(rtext); + } else { + text_obj = desktop->currentLayer()->get_child_by_repr(rtext); + } + Geom::Affine affine = Geom::Affine(Geom::Translate(newpos).inverse()); + affine *= Geom::Rotate(angle); + affine *= Geom::Translate(newpos); + SP_ITEM(text_obj)->transform = affine * i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(desktop->doc()->getRoot())); + text_obj->updateRepr(); } } } @@ -422,49 +316,13 @@ void LPEMeasureLine::doOnRemove (SPLPEItem const* lpeitem) { if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { SPLPEItem * splpeitem = const_cast(lpeitem); - std::vector orientations; - std::vector orientations_remove; - if ( orientation == OM_HORIZONTAL || - orientation == OM_PARALLEL_VERTICAL_HORIZONTAL || - orientation == OM_PARALLEL_HORIZONTAL || - orientation == OM_VERTICAL_HORIZONTAL) - { - orientations.push_back(OM_HORIZONTAL); - } - if ( orientation == OM_VERTICAL || - orientation == OM_PARALLEL_VERTICAL_HORIZONTAL || - orientation == OM_PARALLEL_VERTICAL || - orientation == OM_VERTICAL_HORIZONTAL) - { - orientations.push_back(OM_VERTICAL); - } - if ( orientation == OM_PARALLEL || - orientation == OM_PARALLEL_VERTICAL_HORIZONTAL || - orientation == OM_PARALLEL_VERTICAL || - orientation == OM_PARALLEL_HORIZONTAL) - { - orientations.push_back(OM_PARALLEL); - } - for (std::vector::const_iterator om_it = orientations.begin(); om_it != orientations.end(); ++om_it) { - Glib::ustring orientation_str; - Inkscape::XML::Node *rtext = NULL; - if (*om_it == OM_VERTICAL) { - orientation_str = "vertical"; - } - if (*om_it == OM_HORIZONTAL) { - orientation_str = "horizontal"; - } - if (*om_it == OM_PARALLEL) { - orientation_str = "parallel"; - } - Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_DINnumber_" + orientation_str).c_str()); - Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); - SVGElemRef->attach(SVGElem_uri); - SPObject *elemref = NULL; - Inkscape::XML::Node *rtspan = NULL; - if (elemref = SVGElemRef->getObject()) { - elemref->deleteObject(); - } + Inkscape::URI SVGElem_uri(((Glib::ustring)this->getRepr()->attribute("id") + (Glib::ustring)"_text").c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + Inkscape::XML::Node *rtspan = NULL; + if (elemref = SVGElemRef->getObject()) { + elemref->deleteObject(); } } } @@ -509,40 +367,7 @@ Gtk::Widget *LPEMeasureLine::newWidget() Geom::PathVector LPEMeasureLine::doEffect_path(Geom::PathVector const &path_in) { - Geom::Path path; - Geom::Point s = path_in.initialPoint(); - Geom::Point e = path_in.finalPoint(); - Geom::Ray ray(s,e); - Geom::Coord angle = ray.angle(); - if (reverse) { - angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); - if (angle < 0) angle += 2*M_PI; - } - s = s - Point::polar(angle, gap_start); - angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); - if (angle < 0) angle += 2*M_PI; - e = e - Point::polar(angle, gap_end); -// if(orientation == OM_VERTICAL) { -// Coord xpos = std::max(s[Geom::X],e[Geom::X]); -// if (reverse) { -// xpos = std::min(s[Geom::X],e[Geom::X]); -// } -// s[Geom::X] = xpos; -// e[Geom::X] = xpos; -// } -// if(orientation == OM_HORIZONTAL) { -// Coord ypos = std::max(s[Geom::Y],e[Geom::Y]); -// if (reverse) { -// ypos = std::min(s[Geom::Y],e[Geom::Y]); -// } -// s[Geom::Y] = ypos; -// e[Geom::Y] = ypos; -// } - path.start( s ); - path.appendNew( e ); - Geom::PathVector output; - output.push_back(path); - return output; + return path_in; } void @@ -554,7 +379,6 @@ LPEMeasureLine::saveDefault() prefs->setInt("/live_effects/measure-line/precision", precision); prefs->setDouble("/live_effects/measure-line/offset_right_left", offset_right_left); prefs->setDouble("/live_effects/measure-line/offset_top_bottom", offset_top_bottom); - prefs->setDouble("/live_effects/measure-line/origin_offset", origin_offset); prefs->setString("/live_effects/measure-line/unit", (Glib::ustring)unit.get_abbreviation()); prefs->setBool("/live_effects/measure-line/reverse", reverse); prefs->setBool("/live_effects/measure-line/color_as_line", color_as_line); diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index 05f9b2f73..834194841 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -29,10 +29,6 @@ enum OrientationMethod { OM_HORIZONTAL, OM_VERTICAL, OM_PARALLEL, - OM_PARALLEL_VERTICAL, - OM_PARALLEL_HORIZONTAL, - OM_VERTICAL_HORIZONTAL, - OM_PARALLEL_VERTICAL_HORIZONTAL, OM_END }; @@ -43,29 +39,26 @@ public: virtual void doBeforeEffect (SPLPEItem const* lpeitem); virtual void doOnApply(SPLPEItem const* lpeitem); virtual void doOnRemove (SPLPEItem const* lpeitem); + virtual void doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/); virtual Geom::PathVector doEffect_path(Geom::PathVector const &path_in); void saveDefault(); virtual Gtk::Widget *newWidget(); private: FontButtonParam fontbutton; EnumParam orientation; - OriginalPathParam origin; ScalarParam curve_linked; - ScalarParam origin_offset; ScalarParam scale; ScalarParam precision; ScalarParam offset_right_left; ScalarParam offset_top_bottom; ScalarParam gap_start; ScalarParam gap_end; - size_t previous_ncurves; UnitParam unit; BoolParam reverse; BoolParam color_as_line; BoolParam scale_insensitive; BoolParam local_locale; Glib::ustring doc_unit; - static bool alerts_off; /* Geom::Affine affine_over;*/ LPEMeasureLine(const LPEMeasureLine &); LPEMeasureLine &operator=(const LPEMeasureLine &); diff --git a/src/live_effects/parameter/parameter.cpp b/src/live_effects/parameter/parameter.cpp index 3f8fced4b..befac4df1 100644 --- a/src/live_effects/parameter/parameter.cpp +++ b/src/live_effects/parameter/parameter.cpp @@ -5,8 +5,8 @@ */ -#include "live_effects/parameter/parameter.h" #include "live_effects/effect.h" +#include "live_effects/parameter/parameter.h" #include "svg/svg.h" #include "xml/repr.h" @@ -66,8 +66,7 @@ ScalarParam::ScalarParam( const Glib::ustring& label, const Glib::ustring& tip, inc_page(1), add_slider(false), overwrite_widget(false), - hide_widget(no_widget), - _rsu(NULL) + hide_widget(no_widget) { } @@ -111,6 +110,7 @@ ScalarParam::param_update_default(gdouble default_value) void ScalarParam::param_set_value(gdouble val) { + param_effect->upd_params = true; value = val; if (integer) value = round(value); @@ -118,9 +118,6 @@ ScalarParam::param_set_value(gdouble val) value = max; if (value < min) value = min; - if (_rsu) { - _rsu->setValue(val); - } } void @@ -131,7 +128,7 @@ ScalarParam::param_set_range(gdouble min, gdouble max) // Once again, in gtk2, this is not a problem. But in gtk3, // widgets get allocated the amount of size they ask for, // leading to excessively long widgets. - + param_effect->upd_params = true; if (min >= -SCALARPARAM_G_MAXDOUBLE) { this->min = min; } else { @@ -140,10 +137,7 @@ ScalarParam::param_set_range(gdouble min, gdouble max) if (max <= SCALARPARAM_G_MAXDOUBLE) { this->max = max; } else { - this->max = SCALARPARAM_G_MAXDOUBLE; - } - if (_rsu) { - _rsu->setRange(this->min, this->max); + this->max = SCALARPARAM_G_MAXDOUBLE; } param_set_value(value); // reset value to see whether it is in ranges } @@ -151,6 +145,7 @@ ScalarParam::param_set_range(gdouble min, gdouble max) void ScalarParam::param_make_integer(bool yes) { + param_effect->upd_params = true; integer = yes; digits = 0; inc_step = 1; @@ -167,22 +162,22 @@ Gtk::Widget * ScalarParam::param_newWidget() { if(!hide_widget){ - _rsu = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalar( + Inkscape::UI::Widget::RegisteredScalar *rsu = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalar( param_label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc() ) ); - _rsu->setValue(value); - _rsu->setDigits(digits); - _rsu->setIncrements(inc_step, inc_page); - _rsu->setRange(min, max); - _rsu->setProgrammatically = false; + rsu->setValue(value); + rsu->setDigits(digits); + rsu->setIncrements(inc_step, inc_page); + rsu->setRange(min, max); + rsu->setProgrammatically = false; if (add_slider) { - _rsu->addSlider(); + rsu->addSlider(); } if(!overwrite_widget){ - _rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change scalar parameter")); + rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change scalar parameter")); } param_effect->upd_params = false; - return dynamic_cast (_rsu); + return dynamic_cast (rsu); } else { return NULL; } @@ -191,20 +186,16 @@ ScalarParam::param_newWidget() void ScalarParam::param_set_digits(unsigned digits) { + param_effect->upd_params = true; this->digits = digits; - if (_rsu) { - _rsu->setDigits(this->digits); - } } void ScalarParam::param_set_increments(double step, double page) { + param_effect->upd_params = true; inc_step = step; inc_page = page; - if (_rsu) { - _rsu->setIncrements(inc_step, inc_page); - } } diff --git a/src/live_effects/parameter/parameter.h b/src/live_effects/parameter/parameter.h index 63c55203e..3658bded8 100644 --- a/src/live_effects/parameter/parameter.h +++ b/src/live_effects/parameter/parameter.h @@ -117,7 +117,6 @@ public: void param_set_range(gdouble min, gdouble max); void param_set_digits(unsigned digits); void param_set_increments(double step, double page); - void addSlider(bool add_slider_widget) { add_slider = add_slider_widget; }; void param_overwrite_widget(bool overwrite_widget); @@ -141,7 +140,6 @@ protected: private: ScalarParam(const ScalarParam&); ScalarParam& operator=(const ScalarParam&); - Inkscape::UI::Widget::RegisteredScalar *_rsu; }; } //namespace LivePathEffect -- cgit v1.2.3 From 6ac79a669ea08356806bd130d1426871473b0b71 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 31 Jul 2016 16:02:08 +0200 Subject: Add options to fit on DIN (bzr r15017.1.16) --- src/live_effects/lpe-measure-line.cpp | 515 +++++++++++++++++++++++----------- src/live_effects/lpe-measure-line.h | 18 +- src/live_effects/parameter/text.cpp | 36 ++- src/live_effects/parameter/text.h | 4 +- 4 files changed, 387 insertions(+), 186 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 6d58e2b7d..c2a502e00 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -1,7 +1,8 @@ /* * Author(s): * Jabiertxo Arraiza Cenoz - * + * Some code and ideas migrated from dimensioning.py by + * Johannes B. Rutzmoser, johannes.rutzmoser (at) googlemail (dot) com * Copyright (C) 2014 Author(s) * Released under GNU GPL, read the file 'COPYING' for more information @@ -22,6 +23,7 @@ #include <2geom/affine.h> #include "style.h" #include "sp-root.h" +#include "sp-defs.h" #include "sp-item.h" #include "sp-shape.h" #include "sp-path.h" @@ -50,41 +52,52 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : curve_linked(_("Curve on origin"), _("Curve on origin, set 0 to start/end"), "curve_linked", &wr, this, 1), scale(_("Scale*"), _("Scaling factor"), "scale", &wr, this, 1.0), precision(_("Precision*"), _("Precision"), "precision", &wr, this, 2), - offset_right_left(_("Offset right left*"), _("Offset right left"), "offset_right_left", &wr, this, 0), - offset_top_bottom(_("Offset top bottom*"), _("Offset top bottom"), "offset_top_bottom", &wr, this, 5), - gap_start(_("Gap to line from origin"), _("Gap to line from origin, without affecting measure"), "gap_start", &wr, this, 0), - gap_end(_("Gap to line from end"), _("Gap to line from end, without affecting measure"), "gap_end", &wr, this, 0), + position(_("Positon*"), _("Positon"), "position", &wr, this, 5), + text_distance(_("Text distance*"), _("Text distance"), "text_distance", &wr, this, 12), + helpline_distance(_("Helpline distance*"), _("Helpline distance"), "helpline_distance", &wr, this, 0.0), + helpline_overlap(_("Helpline overlap*"), _("Helpline overlap"), "helpline_overlap", &wr, this, 2.0), unit(_("Unit*"), _("Unit"), "unit", &wr, this), - reverse(_("To other side*"), _("To other side"), "reverse", &wr, this, false), - color_as_line(_("Measure color as line*"), _("Measure color as line"), "color_as_line", &wr, this, false), + format(_("Format*"), _("Format the number ex:measure+ +unit"), "format", &wr, this, "measure+unit"), + arrows_outside(_("Arrows outside"), _("Arrows outside"), "arrows_outside", &wr, this, false), + flip_side(_("Flip side*"), _("Flip side"), "flip_side", &wr, this, false), scale_insensitive(_("Scale insensitive*"), _("Scale insensitive to transforms in element, parents..."), "scale_insensitive", &wr, this, true), - local_locale(_("Local Number Format*"), _("Local number format"), "local_locale", &wr, this, true) + local_locale(_("Local Number Format*"), _("Local number format"), "local_locale", &wr, this, true), + line_group_05(_("Line Group 0.5*"), _("Line Group 0.5, from 0.7"), "line_group_05", &wr, this, true), + rotate_anotation(_("Rotate Anotation*"), _("Rotate Anotation"), "rotate_anotation", &wr, this, true) { registerParameter(&fontbutton); registerParameter(&orientation); registerParameter(&curve_linked); registerParameter(&scale); registerParameter(&precision); - registerParameter(&offset_right_left); - registerParameter(&offset_top_bottom); - registerParameter(&gap_start); - registerParameter(&gap_end); + registerParameter(&position); + registerParameter(&text_distance); + registerParameter(&helpline_distance); + registerParameter(&helpline_overlap); registerParameter(&unit); - registerParameter(&reverse); - registerParameter(&color_as_line); + registerParameter(&format); + registerParameter(&arrows_outside); + registerParameter(&flip_side); registerParameter(&scale_insensitive); registerParameter(&local_locale); + registerParameter(&line_group_05); + registerParameter(&rotate_anotation); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); fontbutton.param_update_default(prefs->getString("/live_effects/measure-line/fontbutton")); scale.param_update_default(prefs->getDouble("/live_effects/measure-line/scale", 1.0)); precision.param_update_default(prefs->getInt("/live_effects/measure-line/precision", 2)); - offset_right_left.param_update_default(prefs->getDouble("/live_effects/measure-line/offset_right_left", 0.0)); - offset_top_bottom.param_update_default(prefs->getDouble("/live_effects/measure-line/offset_top_bottom", 5.0)); + position.param_update_default(prefs->getDouble("/live_effects/measure-line/position", 10.0)); + text_distance.param_update_default(prefs->getDouble("/live_effects/measure-line/text_distance", 5.0)); + helpline_distance.param_update_default(prefs->getDouble("/live_effects/measure-line/helpline_distance", 0.0)); + helpline_overlap.param_update_default(prefs->getDouble("/live_effects/measure-line/helpline_overlap", 0.0)); unit.param_update_default(prefs->getString("/live_effects/measure-line/unit")); - reverse.param_update_default(prefs->getBool("/live_effects/measure-line/reverse")); - color_as_line.param_update_default(prefs->getBool("/live_effects/measure-line/color_as_line")); + format.param_update_default(prefs->getString("/live_effects/measure-line/format")); + flip_side.param_update_default(prefs->getBool("/live_effects/measure-line/flip_side")); scale_insensitive.param_update_default(prefs->getBool("/live_effects/measure-line/scale_insensitive")); local_locale.param_update_default(prefs->getBool("/live_effects/measure-line/local_locale")); + line_group_05.param_update_default(prefs->getBool("/live_effects/measure-line/line_group_05")); + rotate_anotation.param_update_default(prefs->getBool("/live_effects/measure-line/rotate_anotation")); + format.param_hide_canvas_text(); precision.param_set_range(0, 100); precision.param_set_increments(1, 1); precision.param_set_digits(0); @@ -94,18 +107,18 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : curve_linked.param_set_digits(0); curve_linked.param_make_integer(true); precision.param_make_integer(true); - offset_right_left.param_set_range(-999999.0, 999999.0); - offset_right_left.param_set_increments(1, 1); - offset_right_left.param_set_digits(2); - offset_top_bottom.param_set_range(-999999.0, 999999.0); - offset_top_bottom.param_set_increments(1, 1); - offset_top_bottom.param_set_digits(2); - gap_start.param_set_range(-999999.0, 999999.0); - gap_start.param_set_increments(1, 1); - gap_start.param_set_digits(2); - gap_end.param_set_range(-999999.0, 999999.0); - gap_end.param_set_increments(1, 1); - gap_end.param_set_digits(2); + position.param_set_range(-999999.0, 999999.0); + position.param_set_increments(1, 1); + position.param_set_digits(2); + text_distance.param_set_range(-999999.0, 999999.0); + text_distance.param_set_increments(1, 1); + text_distance.param_set_digits(2); + helpline_distance.param_set_range(-999999.0, 999999.0); + helpline_distance.param_set_increments(1, 1); + helpline_distance.param_set_digits(2); + helpline_overlap.param_set_range(-999999.0, 999999.0); + helpline_overlap.param_set_increments(1, 1); + helpline_overlap.param_set_digits(2); } LPEMeasureLine::~LPEMeasureLine() {} @@ -124,7 +137,7 @@ void LPEMeasureLine::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) { if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { - Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)this->getRepr()->attribute("id") + (Glib::ustring)"_text").c_str()); + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)"text-on-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); SVGElemRef->attach(SVGElem_uri); SPObject *elemref = NULL; @@ -140,6 +153,213 @@ LPEMeasureLine::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) } } +void +LPEMeasureLine::createArrowMarker(Glib::ustring mode) +{ + if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { + Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + mode).c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + Inkscape::XML::Node *arrow = NULL; + if (!(elemref = SVGElemRef->getObject())) { + arrow = xml_doc->createElement("svg:marker"); + arrow->setAttribute("id", mode.c_str()); + arrow->setAttribute("inkscape:stockid", mode.c_str()); + arrow->setAttribute("orient", "auto"); + arrow->setAttribute("refX", "0.0"); + arrow->setAttribute("refY", "0.0"); + arrow->setAttribute("style", "overflow:visible"); + /* Create */ + Inkscape::XML::Node *arrow_path = xml_doc->createElement("svg:path"); + if (mode == (Glib::ustring)"ArrowDIN-start") { + arrow_path->setAttribute("d", "M -8,0 8,-2.11 8,2.11 z"); + } else if (mode == (Glib::ustring)"ArrowDIN-end") { + arrow_path->setAttribute("d", "M 8,0 -8,2.11 -8,-2.11 z"); + } else if (mode == (Glib::ustring)"ArrowDINout-start") { + arrow_path->setAttribute("d", "M 0,0 -16,2.11 -16,0.5 -26,0.5 -26,-0.5 -16,-0.5 -16,-2.11 z"); + } else { + arrow_path->setAttribute("d", "M 0,0 16,2.11 16,0.5 26,0.5 26,-0.5 16,-0.5 16,-2.11 z"); + } + arrow_path->setAttribute("id", (mode + (Glib::ustring)"_path").c_str()); + arrow_path->setAttribute("style", "fill:#000000;stroke:none"); + arrow->addChild(arrow_path, NULL); + Inkscape::GC::release(arrow_path); + SPObject * arrow_obj = SP_OBJECT(desktop->getDocument()->getDefs()->appendChildRepr(arrow)); + Inkscape::GC::release(arrow); + } + } +} + +void +LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angle, double fontsize, bool remove) +{ + if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { + Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); + Inkscape::XML::Node *rtext = NULL; + doc_unit = Inkscape::Util::unit_table.getUnit(desktop->doc()->getRoot()->height.unit)->abbr; + if (doc_unit.empty()) { + doc_unit = "px"; + } + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)"text-on-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + Inkscape::XML::Node *rtspan = NULL; + if (elemref = SVGElemRef->getObject()) { + if (remove) { + elemref->deleteObject(); + return; + } + rtext = elemref->getRepr(); + sp_repr_set_svg_double(rtext, "x", pos[Geom::X]); + sp_repr_set_svg_double(rtext, "y", pos[Geom::Y]); + } else { + if (remove) { + return; + } + rtext = xml_doc->createElement("svg:text"); + rtext->setAttribute("xml:space", "preserve"); + rtext->setAttribute("id", ( (Glib::ustring)"text-on-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + sp_repr_set_svg_double(rtext, "x", pos[Geom::X]); + sp_repr_set_svg_double(rtext, "y", pos[Geom::Y]); + rtspan = xml_doc->createElement("svg:tspan"); + rtspan->setAttribute("sodipodi:role", "line"); + } + gchar * transform; + if (rotate_anotation) { + Geom::Affine affine = Geom::Affine(Geom::Translate(pos).inverse()); + affine *= Geom::Rotate(angle); + affine *= Geom::Translate(pos); + transform = sp_svg_transform_write(affine); + } else { + transform = NULL; + } + rtext->setAttribute("transform", transform); + SPCSSAttr *css = sp_repr_css_attr_new(); + Inkscape::FontLister *fontlister = Inkscape::FontLister::get_instance(); + fontlister->fill_css( css, (Glib::ustring)fontbutton.param_getSVGValue() ); + std::stringstream font_size; + font_size.imbue(std::locale::classic()); + font_size << fontsize << "pt"; + sp_repr_css_set_property (css, "font-size", font_size.str().c_str()); + sp_repr_css_set_property (css, "line-height", "125%"); + sp_repr_css_set_property (css, "letter-spacing", "0"); + sp_repr_css_set_property (css, "word-spacing", "0"); + sp_repr_css_set_property (css, "text-align", "center"); + sp_repr_css_set_property (css, "text-anchor", "middle"); + sp_repr_css_set_property (css, "fill", "#000000"); + sp_repr_css_set_property (css, "fill-opacity", "1"); + sp_repr_css_set_property (css, "stroke", "none"); + Glib::ustring css_str; + sp_repr_css_write_string(css,css_str); + if (!rtspan) { + rtspan = rtext->firstChild(); + } + rtspan->setAttribute("style", css_str.c_str()); + sp_repr_css_attr_unref (css); + if (!elemref) { + rtext->addChild(rtspan, NULL); + Inkscape::GC::release(rtspan); + } + length = Inkscape::Util::Quantity::convert(length, doc_unit.c_str(), unit.get_abbreviation()); + std::stringstream length_str; + length_str.precision(precision); + length_str.setf(std::ios::fixed, std::ios::floatfield); + if (local_locale) { + length_str.imbue(std::locale("")); + } else { + length_str.imbue(std::locale::classic()); + } + length_str << std::fixed << length; + length_str << unit.get_abbreviation(); + Inkscape::XML::Node *rstring = NULL; + if (!elemref) { + rstring = xml_doc->createTextNode(length_str.str().c_str()); + rtspan->addChild(rstring, NULL); + Inkscape::GC::release(rstring); + } else { + rstring = rtspan->firstChild(); + rstring->setContent(length_str.str().c_str()); + } + SPObject * text_obj = NULL; + if (!elemref) { + text_obj = SP_OBJECT(desktop->currentLayer()->appendChildRepr(rtext)); + Inkscape::GC::release(rtext); + } + } +} + +void +LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, bool main, bool remove) +{ + if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { + Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + id).c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + Inkscape::XML::Node *line = NULL; + if (!main) { + Geom::Ray ray(start, end); + Geom::Coord angle = ray.angle(); + start = start + Point::polar(angle, helpline_distance ); + end = end + Point::polar(angle, helpline_overlap ); + } + Geom::Path line_path; + line_path.start(start); + line_path.appendNew(end); + Geom::PathVector line_pathv; + line_pathv.push_back(line_path); + gchar * line_str = sp_svg_write_path( line_pathv ); + line_pathv.clear(); + if (elemref = SVGElemRef->getObject()) { + if (remove) { + elemref->deleteObject(); + return; + } + line = elemref->getRepr(); + line->setAttribute("d" , line_str); + } else { + if (remove) { + return; + } + line = xml_doc->createElement("svg:path"); + line->setAttribute("id", id.c_str()); + line->setAttribute("d" , line_str); + } + Glib::ustring style = (Glib::ustring)"stroke:#000000;fill:none;"; + if (main) { + line->setAttribute("inkscape:label", "dinline"); + if (arrows_outside) { + style = style + (Glib::ustring)"marker-start:url(#ArrowDINout-start);marker-end:url(#ArrowDINout-end);"; + } else { + style = style + (Glib::ustring)"marker-start:url(#ArrowDIN-start);marker-end:url(#ArrowDIN-end);"; + } + } else { + line->setAttribute("inkscape:label", "dinhelpline"); + } + std::stringstream stroke_w; + stroke_w.imbue(std::locale::classic()); + if (line_group_05) { + double stroke_width = Inkscape::Util::Quantity::convert(0.25, "mm", doc_unit.c_str()); + stroke_w << stroke_width; + style = style + (Glib::ustring)"stroke-width:" + (Glib::ustring)stroke_w.str(); + } else { + double stroke_width = Inkscape::Util::Quantity::convert(0.35, "mm", doc_unit.c_str()); + stroke_w << stroke_width; + style = style + (Glib::ustring)"stroke-width:" + (Glib::ustring)stroke_w.str(); + } + line->setAttribute("style", style.c_str()); + SPObject * line_obj = NULL; + if (!elemref) { + line_obj = SP_OBJECT(desktop->currentLayer()->appendChildRepr(line)); + Inkscape::GC::release(line); + } + } +} + void LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) { @@ -147,167 +367,99 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) SPPath *sp_path = dynamic_cast(splpeitem); if (sp_path) { Geom::PathVector pathvector = sp_path->get_original_curve()->get_pathvector(); + if (arrows_outside) { + createArrowMarker((Glib::ustring)"ArrowDINout-start"); + createArrowMarker((Glib::ustring)"ArrowDINout-end"); + } else { + createArrowMarker((Glib::ustring)"ArrowDIN-start"); + createArrowMarker((Glib::ustring)"ArrowDIN-end"); + } if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { size_t ncurves = pathvector.curveCount(); curve_linked.param_set_range(0, ncurves); - Geom::Point s = pathvector.initialPoint(); - Geom::Point e = pathvector.finalPoint(); - if (curve_linked) { //0 start-end nodes - s = pathvector.pointAt(curve_linked -1); - e = pathvector.pointAt(curve_linked); + Geom::Point start = pathvector.initialPoint(); + Geom::Point end = pathvector.finalPoint(); + if (curve_linked) { //!0 + start = pathvector.pointAt(curve_linked -1); + end = pathvector.pointAt(curve_linked); + } + Geom::Point hstart = start; + Geom::Point hend = end; + bool remove = false; + if (Geom::are_near(hstart, hend)) { + remove = true; } - Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); - Glib::ustring orientation_str; - Inkscape::XML::Node *rtext = NULL; if (orientation == OM_VERTICAL) { - orientation_str = "vertical"; - Coord xpos = std::max(s[Geom::X],e[Geom::X]); - if (reverse) { - xpos = std::min(s[Geom::X],e[Geom::X]); + Coord xpos = std::max(hstart[Geom::X],hend[Geom::X]); + if (flip_side) { + xpos = std::min(hstart[Geom::X],hend[Geom::X]); } - s[Geom::X] = xpos; - e[Geom::X] = xpos; - if (s[Geom::Y] > e[Geom::Y]) { - swap(s,e); + hstart[Geom::X] = xpos; + hend[Geom::X] = xpos; + if (hstart[Geom::Y] > hend[Geom::Y]) { + swap(hstart,hend); + swap(start,end); + } + if (Geom::are_near(hstart[Geom::Y], hend[Geom::Y])) { + remove = true; } } if (orientation == OM_HORIZONTAL) { - orientation_str = "horizontal"; - Coord ypos = std::max(s[Geom::Y],e[Geom::Y]); - if (reverse) { - ypos = std::min(s[Geom::Y],e[Geom::Y]); + Coord ypos = std::max(hstart[Geom::Y],hend[Geom::Y]); + if (flip_side) { + ypos = std::min(hstart[Geom::Y],hend[Geom::Y]); } - s[Geom::Y] = ypos; - e[Geom::Y] = ypos; - if (s[Geom::X] < e[Geom::X]) { - swap(s,e); + hstart[Geom::Y] = ypos; + hend[Geom::Y] = ypos; + if (hstart[Geom::X] < hend[Geom::X]) { + swap(hstart,hend); + swap(start,end); + } + if (Geom::are_near(hstart[Geom::X], hend[Geom::X])) { + remove = true; } } - if (orientation == OM_PARALLEL) { - orientation_str = "parallel"; - } - double length = Geom::distance(s, e) * scale; - Geom::Point pos = Geom::middle_point(s,e); - Geom::Ray ray(s,e); + double length = Geom::distance(start,end) * scale; + Geom::Point pos = Geom::middle_point(hstart,hend); + Geom::Ray ray(hstart,hend); Geom::Coord angle = ray.angle(); - doc_unit = Inkscape::Util::unit_table.getUnit(desktop->doc()->getRoot()->height.unit)->abbr; - if (reverse) { + if (flip_side) { angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); if (angle < 0) angle += 2*M_PI; } - Geom::Point newpos = pos - Point::polar(angle, offset_right_left); Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); if (angle_cross < 0) angle_cross += 2*M_PI; - newpos = newpos - Point::polar(angle_cross, offset_top_bottom); - Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)this->getRepr()->attribute("id") + (Glib::ustring)"_text").c_str()); - Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); - SVGElemRef->attach(SVGElem_uri); - SPObject *elemref = NULL; - Inkscape::XML::Node *rtspan = NULL; - if (elemref = SVGElemRef->getObject()) { - rtext = elemref->getRepr(); - sp_repr_set_svg_double(rtext, "x", newpos[Geom::X]); - sp_repr_set_svg_double(rtext, "y", newpos[Geom::Y]); - } else { - rtext = xml_doc->createElement("svg:text"); - rtext->setAttribute("xml:space", "preserve"); - rtext->setAttribute("sodipodi:insensitive", "true"); - rtext->setAttribute("id", ((Glib::ustring)this->getRepr()->attribute("id") + (Glib::ustring)"_text").c_str()); - /* Set style */ - sp_repr_set_svg_double(rtext, "x", newpos[Geom::X]); - sp_repr_set_svg_double(rtext, "y", newpos[Geom::Y]); - /* Create */ - rtspan = xml_doc->createElement("svg:tspan"); - rtspan->setAttribute("sodipodi:role", "line"); - } - SPCSSAttr *css = sp_repr_css_attr_new(); + //We get the font size to offset the text to the middle Pango::FontDescription fontdesc((Glib::ustring)fontbutton.param_getSVGValue()); double fontsize = fontdesc.get_size()/Pango::SCALE; - Inkscape::FontLister *fontlister = Inkscape::FontLister::get_instance(); - fontlister->fill_css( css, (Glib::ustring)fontbutton.param_getSVGValue() ); - std::stringstream font_size; - font_size.imbue(std::locale::classic()); - font_size << fontsize << "pt"; - sp_repr_css_set_property (css, "font-size", font_size.str().c_str()); - sp_repr_css_set_property (css, "line-height", "125%"); - sp_repr_css_set_property (css, "letter-spacing", "0"); - sp_repr_css_set_property (css, "word-spacing", "0"); - sp_repr_css_set_property (css, "text-align", "center"); - sp_repr_css_set_property (css, "text-anchor", "middle"); - if (color_as_line) { - if (lpeitem->style) { - if (lpeitem->style->stroke.isPaintserver()) { - SPPaintServer * server = lpeitem->style->getStrokePaintServer(); - if (server) { - Glib::ustring str; - str += "url(#"; - str += server->getId(); - str += ")"; - sp_repr_css_set_property (css, "fill", str.c_str()); - } - } else if (lpeitem->style->stroke.isColor()) { - gchar c[64]; - sp_svg_write_color (c, sizeof(c), lpeitem->style->stroke.value.color.toRGBA32(SP_SCALE24_TO_FLOAT(lpeitem->style->stroke_opacity.value))); - sp_repr_css_set_property (css, "fill", c); - } else { - sp_repr_css_set_property (css, "fill", "#000000"); - } - } else { - sp_repr_css_unset_property (css, "#000000"); - } - } else { - sp_repr_css_set_property (css, "fill", "#000000"); - } - sp_repr_css_set_property (css, "fill-opacity", "1"); - sp_repr_css_set_property (css, "stroke", "none"); - Glib::ustring css_str; - sp_repr_css_write_string(css,css_str); - if (!rtspan) { - rtspan = rtext->firstChild(); - } - rtspan->setAttribute("style", css_str.c_str()); - sp_repr_css_attr_unref (css); - if (!elemref) { - rtext->addChild(rtspan, NULL); - Inkscape::GC::release(rtspan); - } - /* Create TEXT */ + pos = pos - Point::polar(angle_cross, (position + text_distance) - fontsize/2.0); if (!scale_insensitive) { Geom::Affine affinetransform = i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(desktop->doc()->getRoot())); length *= (affinetransform.expansionX() + affinetransform.expansionY()) / 2.0; } - length = Inkscape::Util::Quantity::convert(length, doc_unit.c_str(), unit.get_abbreviation()); - std::stringstream length_str; - length_str.precision(precision); - length_str.setf(std::ios::fixed, std::ios::floatfield); - if (local_locale) { - length_str.imbue(std::locale("")); - } else { - length_str.imbue(std::locale::classic()); + createTextLabel(pos, length, angle, fontsize, remove); + //LINE + double arrow_gap = 8 * Inkscape::Util::Quantity::convert(0.35, "mm", doc_unit.c_str()); + if (line_group_05) { + arrow_gap = 8 * Inkscape::Util::Quantity::convert(0.25, "mm", doc_unit.c_str()); } - length_str << std::fixed << length; - length_str << unit.get_abbreviation(); - Inkscape::XML::Node *rstring = NULL; - if (!elemref) { - rstring = xml_doc->createTextNode(length_str.str().c_str()); - rtspan->addChild(rstring, NULL); - Inkscape::GC::release(rstring); - } else { - rstring = rtspan->firstChild(); - rstring->setContent(length_str.str().c_str()); + if (flip_side) { + arrow_gap *= -1; } - SPObject * text_obj = NULL; - if (!elemref) { - text_obj = SP_OBJECT(desktop->currentLayer()->appendChildRepr(rtext)); - Inkscape::GC::release(rtext); - } else { - text_obj = desktop->currentLayer()->get_child_by_repr(rtext); + angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); + if (angle_cross < 0) angle_cross += 2*M_PI; + hstart = hstart - Point::polar(angle_cross, position); + Glib::ustring id = (Glib::ustring)"infoline-on-start-" + (Glib::ustring)this->getRepr()->attribute("id"); + createLine(start, hstart, id, false, remove); + hend = hend - Point::polar(angle_cross, position); + id = (Glib::ustring)"infoline-on-end-" + (Glib::ustring)this->getRepr()->attribute("id"); + createLine(end, hend, id, false, remove); + if (!arrows_outside) { + hstart = hstart + Point::polar(angle, arrow_gap); + hend = hend - Point::polar(angle, arrow_gap ); } - Geom::Affine affine = Geom::Affine(Geom::Translate(newpos).inverse()); - affine *= Geom::Rotate(angle); - affine *= Geom::Translate(newpos); - SP_ITEM(text_obj)->transform = affine * i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(desktop->doc()->getRoot())); - text_obj->updateRepr(); + id = (Glib::ustring)"infoline-" + (Glib::ustring)this->getRepr()->attribute("id"); + createLine(hstart, hend, id, true, remove); } } } @@ -316,11 +468,28 @@ void LPEMeasureLine::doOnRemove (SPLPEItem const* lpeitem) { if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { SPLPEItem * splpeitem = const_cast(lpeitem); - Inkscape::URI SVGElem_uri(((Glib::ustring)this->getRepr()->attribute("id") + (Glib::ustring)"_text").c_str()); + Inkscape::URI SVGElem_uri(( (Glib::ustring)"text-on-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); SVGElemRef->attach(SVGElem_uri); SPObject *elemref = NULL; - Inkscape::XML::Node *rtspan = NULL; + if (elemref = SVGElemRef->getObject()) { + elemref->deleteObject(); + } + Inkscape::URI SVGElem_uri2(( (Glib::ustring)"infoline-on-end-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + SVGElemRef->attach(SVGElem_uri2); + elemref = NULL; + if (elemref = SVGElemRef->getObject()) { + elemref->deleteObject(); + } + Inkscape::URI SVGElem_uri3(( (Glib::ustring)"infoline-on-start-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + SVGElemRef->attach(SVGElem_uri3); + elemref = NULL; + if (elemref = SVGElemRef->getObject()) { + elemref->deleteObject(); + } + Inkscape::URI SVGElem_uri4(( (Glib::ustring)"infoline-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + SVGElemRef->attach(SVGElem_uri4); + elemref = NULL; if (elemref = SVGElemRef->getObject()) { elemref->deleteObject(); } @@ -377,13 +546,17 @@ LPEMeasureLine::saveDefault() prefs->setString("/live_effects/measure-line/fontbutton", (Glib::ustring)fontbutton.param_getSVGValue()); prefs->setDouble("/live_effects/measure-line/scale", scale); prefs->setInt("/live_effects/measure-line/precision", precision); - prefs->setDouble("/live_effects/measure-line/offset_right_left", offset_right_left); - prefs->setDouble("/live_effects/measure-line/offset_top_bottom", offset_top_bottom); + prefs->setDouble("/live_effects/measure-line/position", position); + prefs->setDouble("/live_effects/measure-line/text_distance", text_distance); + prefs->setDouble("/live_effects/measure-line/helpline_distance", helpline_distance); + prefs->setDouble("/live_effects/measure-line/helpline_overlap", helpline_overlap); prefs->setString("/live_effects/measure-line/unit", (Glib::ustring)unit.get_abbreviation()); - prefs->setBool("/live_effects/measure-line/reverse", reverse); - prefs->setBool("/live_effects/measure-line/color_as_line", color_as_line); + prefs->setString("/live_effects/measure-line/format", (Glib::ustring)format.param_getSVGValue()); + prefs->setBool("/live_effects/measure-line/flip_side", flip_side); prefs->setBool("/live_effects/measure-line/scale_insensitive", scale_insensitive); prefs->setBool("/live_effects/measure-line/local_locale", local_locale); + prefs->setBool("/live_effects/measure-line/line_group_05", line_group_05); + prefs->setBool("/live_effects/measure-line/rotate_anotation", rotate_anotation); } }; //namespace LivePathEffect diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index 834194841..d54859f8c 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -41,6 +41,9 @@ public: virtual void doOnRemove (SPLPEItem const* lpeitem); virtual void doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/); virtual Geom::PathVector doEffect_path(Geom::PathVector const &path_in); + void createLine(Geom::Point start,Geom::Point end,Glib::ustring id, bool main, bool remove); + void createTextLabel(Geom::Point pos, double length, Geom::Coord angle, double fontsize, bool remove); + void createArrowMarker(Glib::ustring mode); void saveDefault(); virtual Gtk::Widget *newWidget(); private: @@ -49,15 +52,18 @@ private: ScalarParam curve_linked; ScalarParam scale; ScalarParam precision; - ScalarParam offset_right_left; - ScalarParam offset_top_bottom; - ScalarParam gap_start; - ScalarParam gap_end; + ScalarParam position; + ScalarParam text_distance; + ScalarParam helpline_distance; + ScalarParam helpline_overlap; UnitParam unit; - BoolParam reverse; - BoolParam color_as_line; + TextParam format; + BoolParam arrows_outside; + BoolParam flip_side; BoolParam scale_insensitive; BoolParam local_locale; + BoolParam line_group_05; + BoolParam rotate_anotation; Glib::ustring doc_unit; /* Geom::Affine affine_over;*/ LPEMeasureLine(const LPEMeasureLine &); diff --git a/src/live_effects/parameter/text.cpp b/src/live_effects/parameter/text.cpp index 234a6174d..e51cf93ab 100644 --- a/src/live_effects/parameter/text.cpp +++ b/src/live_effects/parameter/text.cpp @@ -31,7 +31,8 @@ TextParam::TextParam( const Glib::ustring& label, const Glib::ustring& tip, Effect* effect, const Glib::ustring default_value ) : Parameter(label, tip, key, wr, effect), value(default_value), - defvalue(default_value) + defvalue(default_value), + _hide_canvas_text(false) { SPDesktop *desktop = SP_ACTIVE_DESKTOP; // FIXME: we shouldn't use this! canvas_text = (SPCanvasText *) sp_canvastext_new(desktop->getTempGroup(), desktop, Geom::Point(0,0), ""); @@ -45,10 +46,25 @@ TextParam::param_set_default() param_setValue(defvalue); } +void +TextParam::param_update_default(Glib::ustring default_value) +{ + defvalue = default_value; +} + +void +TextParam::param_hide_canvas_text() +{ + _hide_canvas_text = true; + sp_canvastext_set_text (canvas_text,""); +} + void TextParam::setPos(Geom::Point pos) { - sp_canvastext_set_coords (canvas_text, pos); + if (!_hide_canvas_text) { + sp_canvastext_set_coords (canvas_text, pos); + } } void @@ -63,9 +79,10 @@ TextParam::setPosAndAnchor(const Geom::Piecewise > &pwd2, Point dir = unit_vector(derivative(pwd2_reparam).valueAt(t_reparam)); Point n = -rot90(dir); double angle = Geom::angle_between(dir, Point(1,0)); - - sp_canvastext_set_coords(canvas_text, pos + n * length); - sp_canvastext_set_anchor_manually(canvas_text, std::sin(angle), -std::cos(angle)); + if (!_hide_canvas_text) { + sp_canvastext_set_coords(canvas_text, pos + n * length); + sp_canvastext_set_anchor_manually(canvas_text, std::sin(angle), -std::cos(angle)); + } } void @@ -73,7 +90,9 @@ TextParam::setAnchor(double x_value, double y_value) { anchor_x = x_value; anchor_y = y_value; - sp_canvastext_set_anchor_manually (canvas_text, anchor_x, anchor_y); + if (!_hide_canvas_text) { + sp_canvastext_set_anchor_manually (canvas_text, anchor_x, anchor_y); + } } bool @@ -107,8 +126,9 @@ void TextParam::param_setValue(const Glib::ustring newvalue) { value = newvalue; - - sp_canvastext_set_text (canvas_text, newvalue.c_str()); + if (!_hide_canvas_text) { + sp_canvastext_set_text (canvas_text, newvalue.c_str()); + } } } /* namespace LivePathEffect */ diff --git a/src/live_effects/parameter/text.h b/src/live_effects/parameter/text.h index 62de70eec..553c84c0a 100644 --- a/src/live_effects/parameter/text.h +++ b/src/live_effects/parameter/text.h @@ -40,7 +40,9 @@ public: virtual gchar * param_getSVGValue() const; void param_setValue(const Glib::ustring newvalue); + void param_hide_canvas_text(); virtual void param_set_default(); + void param_update_default(Glib::ustring default_value); void setPos(Geom::Point pos); void setPosAndAnchor(const Geom::Piecewise > &pwd2, const double t, const double length, bool use_curvature = false); @@ -53,7 +55,7 @@ private: TextParam& operator=(const TextParam&); double anchor_x; double anchor_y; - + bool _hide_canvas_text; Glib::ustring value; Glib::ustring defvalue; -- cgit v1.2.3 From cbbb526d842570fb993598537204ba7b6394d68e Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 31 Jul 2016 17:34:33 +0200 Subject: Font and lenght problems in diferent display units solved, also handle uniform scale viewbox (bzr r15017.1.18) --- src/live_effects/lpe-measure-line.cpp | 40 +++++++++++++++++++++++++++-------- src/live_effects/lpe-measure-line.h | 3 ++- 2 files changed, 33 insertions(+), 10 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index c2a502e00..716f15a5e 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -198,9 +198,30 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); Inkscape::XML::Node *rtext = NULL; - doc_unit = Inkscape::Util::unit_table.getUnit(desktop->doc()->getRoot()->height.unit)->abbr; - if (doc_unit.empty()) { - doc_unit = "px"; + double doc_w = desktop->getDocument()->getRoot()->width.value; +// Glib::ustring doc_unit = unit_table.getUnit(desktop->getDocument()->getRoot()->width.unit)->abbr; +// if (doc_unit == "") { +// doc_unit = "px"; +// } else if (doc_unit == "%" && desktop->getDocument()->getRoot()->viewBox_set) { +// doc_w_unit = "px"; +// doc_w = desktop->getDocument()->getRoot()->viewBox.width(); +// } +// doc_unit = Inkscape::Util::unit_table.getUnit(desktop->doc()->getRoot()->height.unit)->abbr; +// if (doc_unit.empty()) { +// doc_unit = "px"; +// } + Geom::Scale scale = desktop->getDocument()->getDocumentScale(); + SPNamedView *nv = desktop->getNamedView(); + Glib::ustring display_unit = nv->display_units->abbr; + if (display_unit.empty()) { + display_unit = "px"; + } + //only check constrain viewbox on X + doc_scale = Inkscape::Util::Quantity::convert( scale[Geom::X], "px", nv->display_units ); + if( doc_scale > 0 ) { + doc_scale= 1.0/doc_scale; + } else { + doc_scale = 1.0; } Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)"text-on-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); @@ -263,7 +284,7 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl rtext->addChild(rtspan, NULL); Inkscape::GC::release(rtspan); } - length = Inkscape::Util::Quantity::convert(length, doc_unit.c_str(), unit.get_abbreviation()); + length = Inkscape::Util::Quantity::convert(length / doc_scale, display_unit.c_str(), unit.get_abbreviation()); std::stringstream length_str; length_str.precision(precision); length_str.setf(std::ios::fixed, std::ios::floatfield); @@ -343,11 +364,11 @@ LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, std::stringstream stroke_w; stroke_w.imbue(std::locale::classic()); if (line_group_05) { - double stroke_width = Inkscape::Util::Quantity::convert(0.25, "mm", doc_unit.c_str()); + double stroke_width = Inkscape::Util::Quantity::convert(0.25 / doc_scale, "mm", display_unit.c_str()); stroke_w << stroke_width; style = style + (Glib::ustring)"stroke-width:" + (Glib::ustring)stroke_w.str(); } else { - double stroke_width = Inkscape::Util::Quantity::convert(0.35, "mm", doc_unit.c_str()); + double stroke_width = Inkscape::Util::Quantity::convert(0.35 / doc_scale, "mm", display_unit.c_str()); stroke_w << stroke_width; style = style + (Glib::ustring)"stroke-width:" + (Glib::ustring)stroke_w.str(); } @@ -419,7 +440,7 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) remove = true; } } - double length = Geom::distance(start,end) * scale; + double length = Geom::distance(hstart,hend) * scale; Geom::Point pos = Geom::middle_point(hstart,hend); Geom::Ray ray(hstart,hend); Geom::Coord angle = ray.angle(); @@ -432,6 +453,7 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) //We get the font size to offset the text to the middle Pango::FontDescription fontdesc((Glib::ustring)fontbutton.param_getSVGValue()); double fontsize = fontdesc.get_size()/Pango::SCALE; + fontsize *= desktop->doc()->getRoot()->c2p.inverse().expansionX(); pos = pos - Point::polar(angle_cross, (position + text_distance) - fontsize/2.0); if (!scale_insensitive) { Geom::Affine affinetransform = i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(desktop->doc()->getRoot())); @@ -439,9 +461,9 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } createTextLabel(pos, length, angle, fontsize, remove); //LINE - double arrow_gap = 8 * Inkscape::Util::Quantity::convert(0.35, "mm", doc_unit.c_str()); + double arrow_gap = 8 * Inkscape::Util::Quantity::convert(0.35 / doc_scale, "mm", display_unit.c_str()); if (line_group_05) { - arrow_gap = 8 * Inkscape::Util::Quantity::convert(0.25, "mm", doc_unit.c_str()); + arrow_gap = 8 * Inkscape::Util::Quantity::convert(0.25 / doc_scale, "mm", display_unit.c_str()); } if (flip_side) { arrow_gap *= -1; diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index d54859f8c..581bbb7e4 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -64,7 +64,8 @@ private: BoolParam local_locale; BoolParam line_group_05; BoolParam rotate_anotation; - Glib::ustring doc_unit; + Glib::ustring display_unit; + double doc_scale; /* Geom::Affine affine_over;*/ LPEMeasureLine(const LPEMeasureLine &); LPEMeasureLine &operator=(const LPEMeasureLine &); -- cgit v1.2.3 From 5697c9788ff67d3382d9df31107daa9b7d2aacd2 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 31 Jul 2016 18:57:35 +0200 Subject: Rotate the text label on down position 180 degree (bzr r15017.1.19) --- src/live_effects/lpe-measure-line.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 716f15a5e..b4ad45092 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -56,7 +56,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : text_distance(_("Text distance*"), _("Text distance"), "text_distance", &wr, this, 12), helpline_distance(_("Helpline distance*"), _("Helpline distance"), "helpline_distance", &wr, this, 0.0), helpline_overlap(_("Helpline overlap*"), _("Helpline overlap"), "helpline_overlap", &wr, this, 2.0), - unit(_("Unit*"), _("Unit"), "unit", &wr, this), + unit(_("Unit*"), _("Unit"), "unit", &wr, this, "px"), format(_("Format*"), _("Format the number ex:measure+ +unit"), "format", &wr, this, "measure+unit"), arrows_outside(_("Arrows outside"), _("Arrows outside"), "arrows_outside", &wr, this, false), flip_side(_("Flip side*"), _("Flip side"), "flip_side", &wr, this, false), @@ -251,7 +251,11 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl gchar * transform; if (rotate_anotation) { Geom::Affine affine = Geom::Affine(Geom::Translate(pos).inverse()); - affine *= Geom::Rotate(angle); + if (std::abs(angle) > rad_from_deg(90) && std::abs(angle) < rad_from_deg(270)) { + angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); + if (angle < 0) angle += 2*M_PI; + } + affine *= Geom::Rotate(std::abs(angle)); affine *= Geom::Translate(pos); transform = sp_svg_transform_write(affine); } else { @@ -448,13 +452,17 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); if (angle < 0) angle += 2*M_PI; } - Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); - if (angle_cross < 0) angle_cross += 2*M_PI; //We get the font size to offset the text to the middle Pango::FontDescription fontdesc((Glib::ustring)fontbutton.param_getSVGValue()); double fontsize = fontdesc.get_size()/Pango::SCALE; fontsize *= desktop->doc()->getRoot()->c2p.inverse().expansionX(); - pos = pos - Point::polar(angle_cross, (position + text_distance) - fontsize/2.0); + Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); + if (angle_cross < 0) angle_cross += 2*M_PI; + if (std::abs(angle) > rad_from_deg(90) && std::abs(angle) < rad_from_deg(270)) { + pos = pos - Point::polar(angle_cross, (position - text_distance) + fontsize/2.0); + } else { + pos = pos - Point::polar(angle_cross, (position + text_distance) - fontsize/2.0); + } if (!scale_insensitive) { Geom::Affine affinetransform = i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(desktop->doc()->getRoot())); length *= (affinetransform.expansionX() + affinetransform.expansionY()) / 2.0; -- cgit v1.2.3 From 372309acc2c71ec2153f58f8ee6917ecf4d5d341 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 31 Jul 2016 19:34:59 +0200 Subject: Fix label positioning (bzr r15017.1.20) --- src/live_effects/lpe-measure-line.cpp | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index b4ad45092..97da89fd1 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -199,17 +199,6 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); Inkscape::XML::Node *rtext = NULL; double doc_w = desktop->getDocument()->getRoot()->width.value; -// Glib::ustring doc_unit = unit_table.getUnit(desktop->getDocument()->getRoot()->width.unit)->abbr; -// if (doc_unit == "") { -// doc_unit = "px"; -// } else if (doc_unit == "%" && desktop->getDocument()->getRoot()->viewBox_set) { -// doc_w_unit = "px"; -// doc_w = desktop->getDocument()->getRoot()->viewBox.width(); -// } -// doc_unit = Inkscape::Util::unit_table.getUnit(desktop->doc()->getRoot()->height.unit)->abbr; -// if (doc_unit.empty()) { -// doc_unit = "px"; -// } Geom::Scale scale = desktop->getDocument()->getDocumentScale(); SPNamedView *nv = desktop->getNamedView(); Glib::ustring display_unit = nv->display_units->abbr; @@ -251,11 +240,13 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl gchar * transform; if (rotate_anotation) { Geom::Affine affine = Geom::Affine(Geom::Translate(pos).inverse()); - if (std::abs(angle) > rad_from_deg(90) && std::abs(angle) < rad_from_deg(270)) { + angle = std::fmod(angle, 2*M_PI); + if (angle < 0) angle += 2*M_PI; + if (angle >= rad_from_deg(90) && angle < rad_from_deg(270)) { angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); if (angle < 0) angle += 2*M_PI; } - affine *= Geom::Rotate(std::abs(angle)); + affine *= Geom::Rotate(angle); affine *= Geom::Translate(pos); transform = sp_svg_transform_write(affine); } else { @@ -458,7 +449,9 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) fontsize *= desktop->doc()->getRoot()->c2p.inverse().expansionX(); Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); if (angle_cross < 0) angle_cross += 2*M_PI; - if (std::abs(angle) > rad_from_deg(90) && std::abs(angle) < rad_from_deg(270)) { + angle = std::fmod(angle, 2*M_PI); + if (angle < 0) angle += 2*M_PI; + if (angle >= rad_from_deg(90) && angle < rad_from_deg(270)) { pos = pos - Point::polar(angle_cross, (position - text_distance) + fontsize/2.0); } else { pos = pos - Point::polar(angle_cross, (position + text_distance) - fontsize/2.0); -- cgit v1.2.3 From 28d25258de5d2274382dbb592f62e21ca8f91729 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 1 Aug 2016 00:47:38 +0200 Subject: Fix text param and alow run from commandline (bzr r15017.1.21) --- src/live_effects/lpe-measure-line.cpp | 32 ++++++++++++++++++++++++-------- src/live_effects/parameter/text.cpp | 20 ++++++++++++-------- 2 files changed, 36 insertions(+), 16 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 97da89fd1..fc2ff0f8b 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -57,7 +57,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : helpline_distance(_("Helpline distance*"), _("Helpline distance"), "helpline_distance", &wr, this, 0.0), helpline_overlap(_("Helpline overlap*"), _("Helpline overlap"), "helpline_overlap", &wr, this, 2.0), unit(_("Unit*"), _("Unit"), "unit", &wr, this, "px"), - format(_("Format*"), _("Format the number ex:measure+ +unit"), "format", &wr, this, "measure+unit"), + format(_("Format*"), _("Format the number ex:{measure} {unit}, return to save"), "format", &wr, this,"measure unit"), arrows_outside(_("Arrows outside"), _("Arrows outside"), "arrows_outside", &wr, this, false), flip_side(_("Flip side*"), _("Flip side"), "flip_side", &wr, this, false), scale_insensitive(_("Scale insensitive*"), _("Scale insensitive to transforms in element, parents..."), "scale_insensitive", &wr, this, true), @@ -83,15 +83,27 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : registerParameter(&line_group_05); registerParameter(&rotate_anotation); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - fontbutton.param_update_default(prefs->getString("/live_effects/measure-line/fontbutton")); + Glib::ustring fontbutton_value = prefs->getString("/live_effects/measure-line/fontbutton"); + if(fontbutton_value.empty()){ + fontbutton_value = "Sans 10"; + } + fontbutton.param_update_default(fontbutton_value); scale.param_update_default(prefs->getDouble("/live_effects/measure-line/scale", 1.0)); precision.param_update_default(prefs->getInt("/live_effects/measure-line/precision", 2)); position.param_update_default(prefs->getDouble("/live_effects/measure-line/position", 10.0)); text_distance.param_update_default(prefs->getDouble("/live_effects/measure-line/text_distance", 5.0)); helpline_distance.param_update_default(prefs->getDouble("/live_effects/measure-line/helpline_distance", 0.0)); helpline_overlap.param_update_default(prefs->getDouble("/live_effects/measure-line/helpline_overlap", 0.0)); - unit.param_update_default(prefs->getString("/live_effects/measure-line/unit")); - format.param_update_default(prefs->getString("/live_effects/measure-line/format")); + Glib::ustring unit_value = prefs->getString("/live_effects/measure-line/unit"); + if(unit_value.empty()){ + unit_value = "px"; + } + unit.param_update_default(unit_value); + Glib::ustring format_value = prefs->getString("/live_effects/measure-line/format"); + if(format_value.empty()){ + format_value = "{measure}{unit}"; + } + format.param_update_default(format_value); flip_side.param_update_default(prefs->getBool("/live_effects/measure-line/flip_side")); scale_insensitive.param_update_default(prefs->getBool("/live_effects/measure-line/scale_insensitive")); local_locale.param_update_default(prefs->getBool("/live_effects/measure-line/local_locale")); @@ -391,6 +403,10 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) createArrowMarker((Glib::ustring)"ArrowDIN-end"); } if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { + if (((Glib::ustring)format.param_getSVGValue()).empty()) { + format.param_setValue((Glib::ustring)"{measure}{unit}"); + this->upd_params = true; + } size_t ncurves = pathvector.curveCount(); curve_linked.param_set_range(0, ncurves); Geom::Point start = pathvector.initialPoint(); @@ -491,26 +507,26 @@ void LPEMeasureLine::doOnRemove (SPLPEItem const* lpeitem) { if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { SPLPEItem * splpeitem = const_cast(lpeitem); - Inkscape::URI SVGElem_uri(( (Glib::ustring)"text-on-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)"text-on-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); SVGElemRef->attach(SVGElem_uri); SPObject *elemref = NULL; if (elemref = SVGElemRef->getObject()) { elemref->deleteObject(); } - Inkscape::URI SVGElem_uri2(( (Glib::ustring)"infoline-on-end-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + Inkscape::URI SVGElem_uri2(((Glib::ustring)"#" + (Glib::ustring)"infoline-on-end-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); SVGElemRef->attach(SVGElem_uri2); elemref = NULL; if (elemref = SVGElemRef->getObject()) { elemref->deleteObject(); } - Inkscape::URI SVGElem_uri3(( (Glib::ustring)"infoline-on-start-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + Inkscape::URI SVGElem_uri3(((Glib::ustring)"#" + (Glib::ustring)"infoline-on-start-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); SVGElemRef->attach(SVGElem_uri3); elemref = NULL; if (elemref = SVGElemRef->getObject()) { elemref->deleteObject(); } - Inkscape::URI SVGElem_uri4(( (Glib::ustring)"infoline-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + Inkscape::URI SVGElem_uri4(((Glib::ustring)"#" + (Glib::ustring)"infoline-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); SVGElemRef->attach(SVGElem_uri4); elemref = NULL; if (elemref = SVGElemRef->getObject()) { diff --git a/src/live_effects/parameter/text.cpp b/src/live_effects/parameter/text.cpp index e51cf93ab..0650b7e66 100644 --- a/src/live_effects/parameter/text.cpp +++ b/src/live_effects/parameter/text.cpp @@ -34,10 +34,13 @@ TextParam::TextParam( const Glib::ustring& label, const Glib::ustring& tip, defvalue(default_value), _hide_canvas_text(false) { - SPDesktop *desktop = SP_ACTIVE_DESKTOP; // FIXME: we shouldn't use this! - canvas_text = (SPCanvasText *) sp_canvastext_new(desktop->getTempGroup(), desktop, Geom::Point(0,0), ""); - sp_canvastext_set_text (canvas_text, default_value.c_str()); - sp_canvastext_set_coords (canvas_text, 0, 0); + if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { // FIXME: we shouldn't use this! + canvas_text = (SPCanvasText *) sp_canvastext_new(desktop->getTempGroup(), desktop, Geom::Point(0,0), ""); + sp_canvastext_set_text (canvas_text, default_value.c_str()); + sp_canvastext_set_coords (canvas_text, 0, 0); + } else { + _hide_canvas_text = true; + } } void @@ -55,8 +58,10 @@ TextParam::param_update_default(Glib::ustring default_value) void TextParam::param_hide_canvas_text() { - _hide_canvas_text = true; - sp_canvastext_set_text (canvas_text,""); + if (!_hide_canvas_text) { + sp_canvastext_set_text(canvas_text, " "); + _hide_canvas_text = true; + } } void @@ -113,8 +118,7 @@ TextParam::param_newWidget() { Inkscape::UI::Widget::RegisteredText *rsu = Gtk::manage(new Inkscape::UI::Widget::RegisteredText( param_label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc())); - - rsu->setText(value.c_str()); + rsu->setText(value); rsu->setProgrammatically = false; rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change text parameter")); -- cgit v1.2.3 From c10966d3ebdac9c920d6329aa4eaca4d450c84da Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 1 Aug 2016 10:50:36 +0200 Subject: Finish format text label (bzr r15017.1.22) --- src/live_effects/lpe-measure-line.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index fc2ff0f8b..ad8a050ea 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -301,15 +301,23 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl length_str.imbue(std::locale::classic()); } length_str << std::fixed << length; - length_str << unit.get_abbreviation(); + Glib::ustring label_value = Glib::ustring(format.param_getSVGValue()); + size_t s = label_value.find((Glib::ustring)"{measure}",0); + if(s < label_value.length()) { + label_value.replace(s,s+9,length_str.str()); + } + s = label_value.find((Glib::ustring)"{unit}",0); + if(s < label_value.length()) { + label_value.replace(s,s+6,unit.get_abbreviation()); + } Inkscape::XML::Node *rstring = NULL; if (!elemref) { - rstring = xml_doc->createTextNode(length_str.str().c_str()); + rstring = xml_doc->createTextNode(label_value.c_str()); rtspan->addChild(rstring, NULL); Inkscape::GC::release(rstring); } else { rstring = rtspan->firstChild(); - rstring->setContent(length_str.str().c_str()); + rstring->setContent(label_value.c_str()); } SPObject * text_obj = NULL; if (!elemref) { -- cgit v1.2.3 From a456c94f4b7e0e385c8a5e89247065804f0abf93 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 1 Aug 2016 16:25:45 +0200 Subject: Add css override style and order widgets (bzr r15017.1.23) --- src/live_effects/lpe-measure-line.cpp | 105 ++++++++++++++++++++++++++++++---- src/live_effects/lpe-measure-line.h | 11 +++- 2 files changed, 102 insertions(+), 14 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index ad8a050ea..1755f0232 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -47,34 +47,39 @@ static const Util::EnumDataConverter OMConverter(OrientationM LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : Effect(lpeobject), + unit(_("Unit*"), _("Unit"), "unit", &wr, this, "px"), fontbutton(_("Font*"), _("Font Selector"), "fontbutton", &wr, this), orientation(_("Orientation"), _("Orientation method"), "orientation", OMConverter, &wr, this, OM_PARALLEL, false), curve_linked(_("Curve on origin"), _("Curve on origin, set 0 to start/end"), "curve_linked", &wr, this, 1), - scale(_("Scale*"), _("Scaling factor"), "scale", &wr, this, 1.0), precision(_("Precision*"), _("Precision"), "precision", &wr, this, 2), position(_("Positon*"), _("Positon"), "position", &wr, this, 5), text_distance(_("Text distance*"), _("Text distance"), "text_distance", &wr, this, 12), helpline_distance(_("Helpline distance*"), _("Helpline distance"), "helpline_distance", &wr, this, 0.0), helpline_overlap(_("Helpline overlap*"), _("Helpline overlap"), "helpline_overlap", &wr, this, 2.0), - unit(_("Unit*"), _("Unit"), "unit", &wr, this, "px"), + scale(_("Scale*"), _("Scaling factor"), "scale", &wr, this, 1.0), format(_("Format*"), _("Format the number ex:{measure} {unit}, return to save"), "format", &wr, this,"measure unit"), arrows_outside(_("Arrows outside"), _("Arrows outside"), "arrows_outside", &wr, this, false), flip_side(_("Flip side*"), _("Flip side"), "flip_side", &wr, this, false), scale_insensitive(_("Scale insensitive*"), _("Scale insensitive to transforms in element, parents..."), "scale_insensitive", &wr, this, true), local_locale(_("Local Number Format*"), _("Local number format"), "local_locale", &wr, this, true), line_group_05(_("Line Group 0.5*"), _("Line Group 0.5, from 0.7"), "line_group_05", &wr, this, true), - rotate_anotation(_("Rotate Anotation*"), _("Rotate Anotation"), "rotate_anotation", &wr, this, true) + rotate_anotation(_("Rotate Anotation*"), _("Rotate Anotation"), "rotate_anotation", &wr, this, true), + dimline_format(_("CSS DIN line*"), _("Override CSS to DIN line, return to save, empty to reset to DIM"), "dimline_format", &wr, this,""), + helperlines_format(_("CSS helpers*"), _("Override CSS to helper lines, return to save, empty to reset to DIM"), "helperlines_format", &wr, this,""), + anotation_format(_("CSS anotation*"), _("Override CSS to anotation text, return to save, empty to reset to DIM"), "anotation_format", &wr, this,""), + arrows_format(_("CSS arrows*"), _("Override CSS to arrows, return to save, empty to reset DIM"), "arrows_format", &wr, this,""), + expanded(false) { + registerParameter(&unit); registerParameter(&fontbutton); registerParameter(&orientation); registerParameter(&curve_linked); - registerParameter(&scale); registerParameter(&precision); registerParameter(&position); registerParameter(&text_distance); registerParameter(&helpline_distance); registerParameter(&helpline_overlap); - registerParameter(&unit); + registerParameter(&scale); registerParameter(&format); registerParameter(&arrows_outside); registerParameter(&flip_side); @@ -82,6 +87,10 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : registerParameter(&local_locale); registerParameter(&line_group_05); registerParameter(&rotate_anotation); + registerParameter(&dimline_format); + registerParameter(&helperlines_format); + registerParameter(&anotation_format); + registerParameter(&arrows_format); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); Glib::ustring fontbutton_value = prefs->getString("/live_effects/measure-line/fontbutton"); if(fontbutton_value.empty()){ @@ -104,6 +113,10 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : format_value = "{measure}{unit}"; } format.param_update_default(format_value); + dimline_format.param_update_default(prefs->getString("/live_effects/measure-line/dimline_format")); + helperlines_format.param_update_default(prefs->getString("/live_effects/measure-line/helperlines_format")); + anotation_format.param_update_default(prefs->getString("/live_effects/measure-line/anotation_format")); + arrows_format.param_update_default(prefs->getString("/live_effects/measure-line/arrows_format")); flip_side.param_update_default(prefs->getBool("/live_effects/measure-line/flip_side")); scale_insensitive.param_update_default(prefs->getBool("/live_effects/measure-line/scale_insensitive")); local_locale.param_update_default(prefs->getBool("/live_effects/measure-line/local_locale")); @@ -195,11 +208,31 @@ LPEMeasureLine::createArrowMarker(Glib::ustring mode) arrow_path->setAttribute("d", "M 0,0 16,2.11 16,0.5 26,0.5 26,-0.5 16,-0.5 16,-2.11 z"); } arrow_path->setAttribute("id", (mode + (Glib::ustring)"_path").c_str()); - arrow_path->setAttribute("style", "fill:#000000;stroke:none"); + SPCSSAttr *css = sp_repr_css_attr_new(); + sp_repr_css_set_property (css, "fill","#000000"); + sp_repr_css_set_property (css, "stroke","none" ); + sp_repr_css_attr_add_from_string(css, arrows_format.param_getSVGValue()); + Glib::ustring css_str; + sp_repr_css_write_string(css,css_str); + arrow_path->setAttribute("style", css_str.c_str()); arrow->addChild(arrow_path, NULL); Inkscape::GC::release(arrow_path); SPObject * arrow_obj = SP_OBJECT(desktop->getDocument()->getDefs()->appendChildRepr(arrow)); Inkscape::GC::release(arrow); + } else { + Inkscape::XML::Node *arrow= elemref->getRepr(); + if (arrow) { + Inkscape::XML::Node *arrow_data = arrow->firstChild(); + if (arrow_data) { + SPCSSAttr *css = sp_repr_css_attr_new(); + sp_repr_css_set_property (css, "fill","#000000"); + sp_repr_css_set_property (css, "stroke","none" ); + sp_repr_css_attr_add_from_string(css, arrows_format.param_getSVGValue()); + Glib::ustring css_str; + sp_repr_css_write_string(css,css_str); + arrow_data->setAttribute("style", css_str.c_str()); + } + } } } } @@ -266,26 +299,29 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl } rtext->setAttribute("transform", transform); SPCSSAttr *css = sp_repr_css_attr_new(); + sp_repr_css_attr_add_from_string(css, anotation_format.param_getSVGValue()); Inkscape::FontLister *fontlister = Inkscape::FontLister::get_instance(); fontlister->fill_css( css, (Glib::ustring)fontbutton.param_getSVGValue() ); std::stringstream font_size; font_size.imbue(std::locale::classic()); font_size << fontsize << "pt"; - sp_repr_css_set_property (css, "font-size", font_size.str().c_str()); - sp_repr_css_set_property (css, "line-height", "125%"); - sp_repr_css_set_property (css, "letter-spacing", "0"); + + sp_repr_css_set_property (css, "font-size",font_size.str().c_str()); + sp_repr_css_set_property (css, "line-height","125%"); + sp_repr_css_set_property (css, "letter-spacing","0"); sp_repr_css_set_property (css, "word-spacing", "0"); sp_repr_css_set_property (css, "text-align", "center"); sp_repr_css_set_property (css, "text-anchor", "middle"); sp_repr_css_set_property (css, "fill", "#000000"); sp_repr_css_set_property (css, "fill-opacity", "1"); sp_repr_css_set_property (css, "stroke", "none"); + sp_repr_css_attr_add_from_string(css, anotation_format.param_getSVGValue()); Glib::ustring css_str; sp_repr_css_write_string(css,css_str); if (!rtspan) { rtspan = rtext->firstChild(); } - rtspan->setAttribute("style", css_str.c_str()); + rtext->setAttribute("style", css_str.c_str()); sp_repr_css_attr_unref (css); if (!elemref) { rtext->addChild(rtspan, NULL); @@ -387,7 +423,16 @@ LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, stroke_w << stroke_width; style = style + (Glib::ustring)"stroke-width:" + (Glib::ustring)stroke_w.str(); } - line->setAttribute("style", style.c_str()); + SPCSSAttr *css = sp_repr_css_attr_new(); + sp_repr_css_attr_add_from_string(css, style.c_str()); + if (main) { + sp_repr_css_attr_add_from_string(css, dimline_format.param_getSVGValue()); + } else { + sp_repr_css_attr_add_from_string(css, helperlines_format.param_getSVGValue()); + } + Glib::ustring css_str; + sp_repr_css_write_string(css,css_str); + line->setAttribute("style", css_str.c_str()); SPObject * line_obj = NULL; if (!elemref) { line_obj = SP_OBJECT(desktop->currentLayer()->appendChildRepr(line)); @@ -490,6 +535,12 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) if (line_group_05) { arrow_gap = 8 * Inkscape::Util::Quantity::convert(0.25 / doc_scale, "mm", display_unit.c_str()); } + SPCSSAttr *css = sp_repr_css_attr_new(); + sp_repr_css_attr_add_from_string(css, dimline_format.param_getSVGValue()); + gchar const * width_line = sp_repr_css_property(css,"stroke-width","-1"); + if (width_line != "-1") { + arrow_gap = 8 * atof(width_line); + } if (flip_side) { arrow_gap *= -1; } @@ -555,13 +606,23 @@ Gtk::Widget *LPEMeasureLine::newWidget() std::vector::iterator it = param_vector.begin(); Gtk::HBox * button1 = Gtk::manage(new Gtk::HBox(true,0)); + Gtk::VBox * vbox_expander = Gtk::manage( new Gtk::VBox(Effect::newWidget()) ); + vbox_expander->set_border_width(0); + vbox_expander->set_spacing(2); while (it != param_vector.end()) { if ((*it)->widget_is_visible) { Parameter *param = *it; Gtk::Widget *widg = dynamic_cast(param->param_newWidget()); Glib::ustring *tip = param->param_getTooltip(); if (widg) { - vbox->pack_start(*widg, true, true, 2); + if (param->param_key != "dimline_format" && + param->param_key != "helperlines_format" && + param->param_key != "arrows_format" && + param->param_key != "anotation_format") { + vbox->pack_start(*widg, true, true, 2); + } else { + vbox_expander->pack_start(*widg, true, true, 2); + } if (tip) { widg->set_tooltip_text(*tip); } else { @@ -576,10 +637,26 @@ Gtk::Widget *LPEMeasureLine::newWidget() Gtk::Button *save_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Save '*' as default")))); save_default->signal_clicked().connect(sigc::mem_fun(*this, &LPEMeasureLine::saveDefault)); button1->pack_start(*save_default, true, true, 2); + expander = Gtk::manage(new Gtk::Expander(Glib::ustring(_("Show DIM CSS style override")))); + expander->add(*vbox_expander); + expander->set_expanded(expanded); + expander->property_expanded().signal_changed().connect(sigc::mem_fun(*this, &LPEMeasureLine::onExpanderChanged) ); + vbox->pack_start(*expander, true, true, 2); vbox->pack_start(*button1, true, true, 2); return dynamic_cast(vbox); } +void +LPEMeasureLine::onExpanderChanged() +{ + expanded = expander->get_expanded(); + if(expanded) { + expander->set_label (Glib::ustring(_("Hide DIM CSS style override"))); + } else { + expander->set_label (Glib::ustring(_("Show DIM CSS style override"))); + } +} + Geom::PathVector LPEMeasureLine::doEffect_path(Geom::PathVector const &path_in) { @@ -599,6 +676,10 @@ LPEMeasureLine::saveDefault() prefs->setDouble("/live_effects/measure-line/helpline_overlap", helpline_overlap); prefs->setString("/live_effects/measure-line/unit", (Glib::ustring)unit.get_abbreviation()); prefs->setString("/live_effects/measure-line/format", (Glib::ustring)format.param_getSVGValue()); + prefs->setString("/live_effects/measure-line/dimline_format", (Glib::ustring)dimline_format.param_getSVGValue()); + prefs->setString("/live_effects/measure-line/helperlines_format", (Glib::ustring)helperlines_format.param_getSVGValue()); + prefs->setString("/live_effects/measure-line/anotation_format", (Glib::ustring)anotation_format.param_getSVGValue()); + prefs->setString("/live_effects/measure-line/arrows_format", (Glib::ustring)arrows_format.param_getSVGValue()); prefs->setBool("/live_effects/measure-line/flip_side", flip_side); prefs->setBool("/live_effects/measure-line/scale_insensitive", scale_insensitive); prefs->setBool("/live_effects/measure-line/local_locale", local_locale); diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index 581bbb7e4..7e9bfabc7 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -43,20 +43,21 @@ public: virtual Geom::PathVector doEffect_path(Geom::PathVector const &path_in); void createLine(Geom::Point start,Geom::Point end,Glib::ustring id, bool main, bool remove); void createTextLabel(Geom::Point pos, double length, Geom::Coord angle, double fontsize, bool remove); + void onExpanderChanged(); void createArrowMarker(Glib::ustring mode); void saveDefault(); virtual Gtk::Widget *newWidget(); private: + UnitParam unit; FontButtonParam fontbutton; EnumParam orientation; ScalarParam curve_linked; - ScalarParam scale; ScalarParam precision; ScalarParam position; ScalarParam text_distance; ScalarParam helpline_distance; ScalarParam helpline_overlap; - UnitParam unit; + ScalarParam scale; TextParam format; BoolParam arrows_outside; BoolParam flip_side; @@ -64,7 +65,13 @@ private: BoolParam local_locale; BoolParam line_group_05; BoolParam rotate_anotation; + TextParam dimline_format; + TextParam helperlines_format; + TextParam anotation_format; + TextParam arrows_format; Glib::ustring display_unit; + bool expanded; + Gtk::Expander * expander; double doc_scale; /* Geom::Affine affine_over;*/ LPEMeasureLine(const LPEMeasureLine &); -- cgit v1.2.3 From fcfd11a606e3951121e2ff1cee46c60ce8d02c9b Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 1 Aug 2016 16:50:33 +0200 Subject: Hide canvas text from some text input (bzr r15017.1.24) --- src/live_effects/lpe-measure-line.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 1755f0232..b84169480 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -123,6 +123,10 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : line_group_05.param_update_default(prefs->getBool("/live_effects/measure-line/line_group_05")); rotate_anotation.param_update_default(prefs->getBool("/live_effects/measure-line/rotate_anotation")); format.param_hide_canvas_text(); + dimline_format.param_hide_canvas_text(); + helperlines_format.param_hide_canvas_text(); + anotation_format.param_hide_canvas_text(); + arrows_format.param_hide_canvas_text(); precision.param_set_range(0, 100); precision.param_set_increments(1, 1); precision.param_set_digits(0); -- cgit v1.2.3 From b7556c8456244e9cc884f721d8a728c1377d565e Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 1 Aug 2016 18:11:45 +0200 Subject: Noumerous bug fixes, font size, stroke with arroow position, and text input response (bzr r15017.1.25) --- src/live_effects/lpe-measure-line.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index b84169480..80d8cb645 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -518,7 +518,7 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } //We get the font size to offset the text to the middle Pango::FontDescription fontdesc((Glib::ustring)fontbutton.param_getSVGValue()); - double fontsize = fontdesc.get_size()/Pango::SCALE; + double fontsize = fontdesc.get_size()/(double)Pango::SCALE; fontsize *= desktop->doc()->getRoot()->c2p.inverse().expansionX(); Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); if (angle_cross < 0) angle_cross += 2*M_PI; @@ -541,13 +541,16 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } SPCSSAttr *css = sp_repr_css_attr_new(); sp_repr_css_attr_add_from_string(css, dimline_format.param_getSVGValue()); - gchar const * width_line = sp_repr_css_property(css,"stroke-width","-1"); - if (width_line != "-1") { - arrow_gap = 8 * atof(width_line); + std::setlocale(LC_NUMERIC, std::locale::classic().name().c_str()); + double width_line = atof(sp_repr_css_property(css,"stroke-width","-1")); + std::setlocale(LC_NUMERIC, std::locale("").name().c_str()); + if (width_line > -0.0001) { + arrow_gap = 8 * Inkscape::Util::Quantity::convert(width_line/ doc_scale, "mm", display_unit.c_str()); } if (flip_side) { arrow_gap *= -1; } + std::cout << arrow_gap << "arrow_gap\n"; angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); if (angle_cross < 0) angle_cross += 2*M_PI; hstart = hstart - Point::polar(angle_cross, position); -- cgit v1.2.3 From 149d77a628b55077399365b420c27e7edc36d6ec Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 1 Aug 2016 18:17:30 +0200 Subject: Remove a helper cout (bzr r15017.1.26) --- src/live_effects/lpe-measure-line.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 80d8cb645..c78475fe8 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -550,7 +550,6 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) if (flip_side) { arrow_gap *= -1; } - std::cout << arrow_gap << "arrow_gap\n"; angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); if (angle_cross < 0) angle_cross += 2*M_PI; hstart = hstart - Point::polar(angle_cross, position); -- cgit v1.2.3 From 2bf9d069f2861ed7dce253a04c2df21a7e387b29 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 1 Aug 2016 18:27:21 +0200 Subject: Fix to hidde all elements when hide the effect (bzr r15017.1.27) --- src/live_effects/lpe-measure-line.cpp | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index c78475fe8..792b0a512 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -179,6 +179,45 @@ LPEMeasureLine::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) rtext->setAttribute("style", NULL); } } + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)"infoline-on-start-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + Inkscape::XML::Node *rtext = NULL; + if (elemref = SVGElemRef->getObject()) { + rtext = elemref->getRepr(); + if (!this->isVisible()) { + rtext->setAttribute("style", "display:none"); + } else { + rtext->setAttribute("style", NULL); + } + } + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)"infoline-on-end-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + Inkscape::XML::Node *rtext = NULL; + if (elemref = SVGElemRef->getObject()) { + rtext = elemref->getRepr(); + if (!this->isVisible()) { + rtext->setAttribute("style", "display:none"); + } else { + rtext->setAttribute("style", NULL); + } + } + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)"infoline-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + Inkscape::XML::Node *rtext = NULL; + if (elemref = SVGElemRef->getObject()) { + rtext = elemref->getRepr(); + if (!this->isVisible()) { + rtext->setAttribute("style", "display:none"); + } else { + rtext->setAttribute("style", NULL); + } + } } } -- cgit v1.2.3 From e4f398171b8da1b990125dfc44277c886212702c Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 1 Aug 2016 18:34:14 +0200 Subject: Fixed compiling bug (bzr r15017.1.28) --- src/live_effects/lpe-measure-line.cpp | 53 +++++++++++++++++------------------ 1 file changed, 25 insertions(+), 28 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 792b0a512..5e638c4e4 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -170,52 +170,49 @@ LPEMeasureLine::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); SVGElemRef->attach(SVGElem_uri); SPObject *elemref = NULL; - Inkscape::XML::Node *rtext = NULL; + Inkscape::XML::Node *node = NULL; if (elemref = SVGElemRef->getObject()) { - rtext = elemref->getRepr(); + node = elemref->getRepr(); if (!this->isVisible()) { - rtext->setAttribute("style", "display:none"); + node->setAttribute("style", "display:none"); } else { - rtext->setAttribute("style", NULL); + node->setAttribute("style", NULL); } } - Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)"infoline-on-start-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); - Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); - SVGElemRef->attach(SVGElem_uri); - SPObject *elemref = NULL; - Inkscape::XML::Node *rtext = NULL; + Inkscape::URI SVGElem_uri2(((Glib::ustring)"#" + (Glib::ustring)"infoline-on-start-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + SVGElemRef->attach(SVGElem_uri2); + elemref = NULL; + node = NULL; if (elemref = SVGElemRef->getObject()) { - rtext = elemref->getRepr(); + node = elemref->getRepr(); if (!this->isVisible()) { - rtext->setAttribute("style", "display:none"); + node->setAttribute("style", "display:none"); } else { - rtext->setAttribute("style", NULL); + node->setAttribute("style", NULL); } } - Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)"infoline-on-end-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); - Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); - SVGElemRef->attach(SVGElem_uri); - SPObject *elemref = NULL; - Inkscape::XML::Node *rtext = NULL; + Inkscape::URI SVGElem_uri3(((Glib::ustring)"#" + (Glib::ustring)"infoline-on-end-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + SVGElemRef->attach(SVGElem_uri3); + elemref = NULL; + node = NULL; if (elemref = SVGElemRef->getObject()) { - rtext = elemref->getRepr(); + node = elemref->getRepr(); if (!this->isVisible()) { - rtext->setAttribute("style", "display:none"); + node->setAttribute("style", "display:none"); } else { - rtext->setAttribute("style", NULL); + node->setAttribute("style", NULL); } } - Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)"infoline-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); - Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); - SVGElemRef->attach(SVGElem_uri); - SPObject *elemref = NULL; - Inkscape::XML::Node *rtext = NULL; + Inkscape::URI SVGElem_uri4(((Glib::ustring)"#" + (Glib::ustring)"infoline-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + SVGElemRef->attach(SVGElem_uri4); + elemref = NULL; + node = NULL; if (elemref = SVGElemRef->getObject()) { - rtext = elemref->getRepr(); + node = elemref->getRepr(); if (!this->isVisible()) { - rtext->setAttribute("style", "display:none"); + node->setAttribute("style", "display:none"); } else { - rtext->setAttribute("style", NULL); + node->setAttribute("style", NULL); } } } -- cgit v1.2.3 From dd30b0318f3f943bab0613d8284cf8c8ad2a089a Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 1 Aug 2016 18:58:17 +0200 Subject: Attem to fix the locale error (bzr r15017.1.29) --- src/live_effects/lpe-measure-line.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 5e638c4e4..fb4530abd 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -29,6 +29,7 @@ #include "sp-path.h" #include "desktop.h" #include "document.h" +#include #include // TODO due to internal breakage in glibmm headers, this must be last: -- cgit v1.2.3 From 390ac12b6a0e6bbc89e34125692d60c44546e94a Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 1 Aug 2016 19:15:46 +0200 Subject: Fix set locale to some compilers folowing su_v help (bzr r15017.1.30) --- src/live_effects/lpe-measure-line.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index fb4530abd..e9e2183e7 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -29,7 +29,6 @@ #include "sp-path.h" #include "desktop.h" #include "document.h" -#include #include // TODO due to internal breakage in glibmm headers, this must be last: @@ -578,9 +577,9 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } SPCSSAttr *css = sp_repr_css_attr_new(); sp_repr_css_attr_add_from_string(css, dimline_format.param_getSVGValue()); - std::setlocale(LC_NUMERIC, std::locale::classic().name().c_str()); + setlocale(LC_NUMERIC, std::locale::classic().name().c_str()); double width_line = atof(sp_repr_css_property(css,"stroke-width","-1")); - std::setlocale(LC_NUMERIC, std::locale("").name().c_str()); + setlocale(LC_NUMERIC, std::locale("").name().c_str()); if (width_line > -0.0001) { arrow_gap = 8 * Inkscape::Util::Quantity::convert(width_line/ doc_scale, "mm", display_unit.c_str()); } -- cgit v1.2.3 From 3b643ec9eff097b88dc4658a9652e67734f3d803 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 1 Aug 2016 19:36:57 +0200 Subject: Credits improvements (bzr r15017.1.31) --- src/live_effects/lpe-measure-line.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index e9e2183e7..ddce17cdf 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -3,6 +3,7 @@ * Jabiertxo Arraiza Cenoz * Some code and ideas migrated from dimensioning.py by * Johannes B. Rutzmoser, johannes.rutzmoser (at) googlemail (dot) com + * https://github.com/Rutzmoser/inkscape_dimensioning * Copyright (C) 2014 Author(s) * Released under GNU GPL, read the file 'COPYING' for more information -- cgit v1.2.3 From 7275e687fcaee5608b7e53481b73cb0b3d254dbe Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 2 Aug 2016 11:19:13 +0200 Subject: Add split DIN line if anottation over (bzr r15017.1.32) --- src/live_effects/lpe-measure-line.cpp | 112 ++++++++++++++++++++++------------ src/live_effects/lpe-measure-line.h | 9 ++- 2 files changed, 79 insertions(+), 42 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index ddce17cdf..393961a13 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -54,7 +54,8 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : curve_linked(_("Curve on origin"), _("Curve on origin, set 0 to start/end"), "curve_linked", &wr, this, 1), precision(_("Precision*"), _("Precision"), "precision", &wr, this, 2), position(_("Positon*"), _("Positon"), "position", &wr, this, 5), - text_distance(_("Text distance*"), _("Text distance"), "text_distance", &wr, this, 12), + text_top_bottom(_("Text top/bottom*"), _("Text top/bottom"), "text_top_bottom", &wr, this, 0), + text_right_left(_("Text right/left*"), _("Text right/left"), "text_right_left", &wr, this, 0), helpline_distance(_("Helpline distance*"), _("Helpline distance"), "helpline_distance", &wr, this, 0.0), helpline_overlap(_("Helpline overlap*"), _("Helpline overlap"), "helpline_overlap", &wr, this, 2.0), scale(_("Scale*"), _("Scaling factor"), "scale", &wr, this, 1.0), @@ -65,6 +66,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : local_locale(_("Local Number Format*"), _("Local number format"), "local_locale", &wr, this, true), line_group_05(_("Line Group 0.5*"), _("Line Group 0.5, from 0.7"), "line_group_05", &wr, this, true), rotate_anotation(_("Rotate Anotation*"), _("Rotate Anotation"), "rotate_anotation", &wr, this, true), + hide_back(_("Hide if label over*"), _("Hide DIN line if label over"), "hide_back", &wr, this, true), dimline_format(_("CSS DIN line*"), _("Override CSS to DIN line, return to save, empty to reset to DIM"), "dimline_format", &wr, this,""), helperlines_format(_("CSS helpers*"), _("Override CSS to helper lines, return to save, empty to reset to DIM"), "helperlines_format", &wr, this,""), anotation_format(_("CSS anotation*"), _("Override CSS to anotation text, return to save, empty to reset to DIM"), "anotation_format", &wr, this,""), @@ -77,7 +79,8 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : registerParameter(&curve_linked); registerParameter(&precision); registerParameter(&position); - registerParameter(&text_distance); + registerParameter(&text_top_bottom); + registerParameter(&text_right_left); registerParameter(&helpline_distance); registerParameter(&helpline_overlap); registerParameter(&scale); @@ -88,6 +91,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : registerParameter(&local_locale); registerParameter(&line_group_05); registerParameter(&rotate_anotation); + registerParameter(&hide_back); registerParameter(&dimline_format); registerParameter(&helperlines_format); registerParameter(&anotation_format); @@ -101,7 +105,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : scale.param_update_default(prefs->getDouble("/live_effects/measure-line/scale", 1.0)); precision.param_update_default(prefs->getInt("/live_effects/measure-line/precision", 2)); position.param_update_default(prefs->getDouble("/live_effects/measure-line/position", 10.0)); - text_distance.param_update_default(prefs->getDouble("/live_effects/measure-line/text_distance", 5.0)); + text_top_bottom.param_update_default(prefs->getDouble("/live_effects/measure-line/text_top_bottom", 5.0)); helpline_distance.param_update_default(prefs->getDouble("/live_effects/measure-line/helpline_distance", 0.0)); helpline_overlap.param_update_default(prefs->getDouble("/live_effects/measure-line/helpline_overlap", 0.0)); Glib::ustring unit_value = prefs->getString("/live_effects/measure-line/unit"); @@ -123,6 +127,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : local_locale.param_update_default(prefs->getBool("/live_effects/measure-line/local_locale")); line_group_05.param_update_default(prefs->getBool("/live_effects/measure-line/line_group_05")); rotate_anotation.param_update_default(prefs->getBool("/live_effects/measure-line/rotate_anotation")); + hide_back.param_update_default(prefs->getBool("/live_effects/measure-line/hide_back")); format.param_hide_canvas_text(); dimline_format.param_hide_canvas_text(); helperlines_format.param_hide_canvas_text(); @@ -140,9 +145,12 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : position.param_set_range(-999999.0, 999999.0); position.param_set_increments(1, 1); position.param_set_digits(2); - text_distance.param_set_range(-999999.0, 999999.0); - text_distance.param_set_increments(1, 1); - text_distance.param_set_digits(2); + text_top_bottom.param_set_range(-999999.0, 999999.0); + text_top_bottom.param_set_increments(1, 1); + text_top_bottom.param_set_digits(2); + text_right_left.param_set_range(-999999.0, 999999.0); + text_right_left.param_set_increments(1, 1); + text_right_left.param_set_digits(2); helpline_distance.param_set_range(-999999.0, 999999.0); helpline_distance.param_set_increments(1, 1); helpline_distance.param_set_digits(2); @@ -182,8 +190,6 @@ LPEMeasureLine::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) } Inkscape::URI SVGElem_uri2(((Glib::ustring)"#" + (Glib::ustring)"infoline-on-start-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); SVGElemRef->attach(SVGElem_uri2); - elemref = NULL; - node = NULL; if (elemref = SVGElemRef->getObject()) { node = elemref->getRepr(); if (!this->isVisible()) { @@ -194,8 +200,6 @@ LPEMeasureLine::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) } Inkscape::URI SVGElem_uri3(((Glib::ustring)"#" + (Glib::ustring)"infoline-on-end-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); SVGElemRef->attach(SVGElem_uri3); - elemref = NULL; - node = NULL; if (elemref = SVGElemRef->getObject()) { node = elemref->getRepr(); if (!this->isVisible()) { @@ -206,8 +210,6 @@ LPEMeasureLine::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) } Inkscape::URI SVGElem_uri4(((Glib::ustring)"#" + (Glib::ustring)"infoline-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); SVGElemRef->attach(SVGElem_uri4); - elemref = NULL; - node = NULL; if (elemref = SVGElemRef->getObject()) { node = elemref->getRepr(); if (!this->isVisible()) { @@ -258,7 +260,7 @@ LPEMeasureLine::createArrowMarker(Glib::ustring mode) arrow_path->setAttribute("style", css_str.c_str()); arrow->addChild(arrow_path, NULL); Inkscape::GC::release(arrow_path); - SPObject * arrow_obj = SP_OBJECT(desktop->getDocument()->getDefs()->appendChildRepr(arrow)); + elemref = SP_OBJECT(desktop->getDocument()->getDefs()->appendChildRepr(arrow)); Inkscape::GC::release(arrow); } else { Inkscape::XML::Node *arrow= elemref->getRepr(); @@ -279,7 +281,7 @@ LPEMeasureLine::createArrowMarker(Glib::ustring mode) } void -LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angle, double fontsize, bool remove) +LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angle, bool remove) { if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); @@ -324,16 +326,16 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl rtspan->setAttribute("sodipodi:role", "line"); } gchar * transform; - if (rotate_anotation) { - Geom::Affine affine = Geom::Affine(Geom::Translate(pos).inverse()); - angle = std::fmod(angle, 2*M_PI); + Geom::Affine affine = Geom::Affine(Geom::Translate(pos).inverse()); + angle = std::fmod(angle, 2*M_PI); + if (angle < 0) angle += 2*M_PI; + if (angle >= rad_from_deg(90) && angle < rad_from_deg(270)) { + angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); if (angle < 0) angle += 2*M_PI; - if (angle >= rad_from_deg(90) && angle < rad_from_deg(270)) { - angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); - if (angle < 0) angle += 2*M_PI; - } - affine *= Geom::Rotate(angle); - affine *= Geom::Translate(pos); + } + affine *= Geom::Rotate(angle); + affine *= Geom::Translate(pos); + if (rotate_anotation) { transform = sp_svg_transform_write(affine); } else { transform = NULL; @@ -363,6 +365,7 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl rtspan = rtext->firstChild(); } rtext->setAttribute("style", css_str.c_str()); + rtspan->setAttribute("style", NULL); sp_repr_css_attr_unref (css); if (!elemref) { rtext->addChild(rtspan, NULL); @@ -396,11 +399,21 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl rstring = rtspan->firstChild(); rstring->setContent(label_value.c_str()); } - SPObject * text_obj = NULL; if (!elemref) { - text_obj = SP_OBJECT(desktop->currentLayer()->appendChildRepr(rtext)); + elemref = SP_OBJECT(desktop->currentLayer()->appendChildRepr(rtext)); Inkscape::GC::release(rtext); } + Inkscape::XML::Node *tmp_node = rtext->duplicate(xml_doc); + affine = Geom::Affine(Geom::Scale(1.1)); + tmp_node->setAttribute("transform", sp_svg_transform_write(affine)); + SPObject * tmp_obj = SP_OBJECT(desktop->currentLayer()->appendChildRepr(tmp_node)); + Inkscape::GC::release(tmp_node); + tmp_obj->updateRepr(); + Geom::OptRect bounds = SP_ITEM(tmp_obj)->bounds(SPItem::GEOMETRIC_BBOX); + if (bounds) { + anotation_width = bounds->width(); + } + tmp_obj->deleteObject(); } } @@ -420,11 +433,33 @@ LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, start = start + Point::polar(angle, helpline_distance ); end = end + Point::polar(angle, helpline_overlap ); } - Geom::Path line_path; - line_path.start(start); - line_path.appendNew(end); Geom::PathVector line_pathv; - line_pathv.push_back(line_path); + if (main && std::abs(text_top_bottom) < fontsize/1.5 && hide_back){ + Geom::Path line_path; + double k = 0; + if (flip_side) { + k = (Geom::distance(start,end)/2.0) + arrow_gap - (anotation_width/2.0); + } else { + k = (Geom::distance(start,end)/2.0) - arrow_gap - (anotation_width/2.0); + } + if (Geom::distance(start,end) < anotation_width){ + return; + } + Geom::Ray ray(end, start); + Geom::Coord angle = ray.angle(); + line_path.start(start); + line_path.appendNew(start - Point::polar(angle, k)); + line_pathv.push_back(line_path); + line_path.clear(); + line_path.start(end + Point::polar(angle, k)); + line_path.appendNew(end); + line_pathv.push_back(line_path); + } else { + Geom::Path line_path; + line_path.start(start); + line_path.appendNew(end); + line_pathv.push_back(line_path); + } gchar * line_str = sp_svg_write_path( line_pathv ); line_pathv.clear(); if (elemref = SVGElemRef->getObject()) { @@ -474,9 +509,8 @@ LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, Glib::ustring css_str; sp_repr_css_write_string(css,css_str); line->setAttribute("style", css_str.c_str()); - SPObject * line_obj = NULL; if (!elemref) { - line_obj = SP_OBJECT(desktop->currentLayer()->appendChildRepr(line)); + elemref = SP_OBJECT(desktop->currentLayer()->appendChildRepr(line)); Inkscape::GC::release(line); } } @@ -555,24 +589,24 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } //We get the font size to offset the text to the middle Pango::FontDescription fontdesc((Glib::ustring)fontbutton.param_getSVGValue()); - double fontsize = fontdesc.get_size()/(double)Pango::SCALE; + fontsize = fontdesc.get_size()/(double)Pango::SCALE; fontsize *= desktop->doc()->getRoot()->c2p.inverse().expansionX(); Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); if (angle_cross < 0) angle_cross += 2*M_PI; angle = std::fmod(angle, 2*M_PI); if (angle < 0) angle += 2*M_PI; if (angle >= rad_from_deg(90) && angle < rad_from_deg(270)) { - pos = pos - Point::polar(angle_cross, (position - text_distance) + fontsize/2.0); + pos = pos - Point::polar(angle_cross, (position - text_top_bottom) + fontsize/2.5); } else { - pos = pos - Point::polar(angle_cross, (position + text_distance) - fontsize/2.0); + pos = pos - Point::polar(angle_cross, (position + text_top_bottom) - fontsize/2.5); } if (!scale_insensitive) { Geom::Affine affinetransform = i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(desktop->doc()->getRoot())); length *= (affinetransform.expansionX() + affinetransform.expansionY()) / 2.0; } - createTextLabel(pos, length, angle, fontsize, remove); + createTextLabel(pos, length, angle, remove); //LINE - double arrow_gap = 8 * Inkscape::Util::Quantity::convert(0.35 / doc_scale, "mm", display_unit.c_str()); + arrow_gap = 8 * Inkscape::Util::Quantity::convert(0.35 / doc_scale, "mm", display_unit.c_str()); if (line_group_05) { arrow_gap = 8 * Inkscape::Util::Quantity::convert(0.25 / doc_scale, "mm", display_unit.c_str()); } @@ -618,19 +652,16 @@ void LPEMeasureLine::doOnRemove (SPLPEItem const* lpeitem) } Inkscape::URI SVGElem_uri2(((Glib::ustring)"#" + (Glib::ustring)"infoline-on-end-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); SVGElemRef->attach(SVGElem_uri2); - elemref = NULL; if (elemref = SVGElemRef->getObject()) { elemref->deleteObject(); } Inkscape::URI SVGElem_uri3(((Glib::ustring)"#" + (Glib::ustring)"infoline-on-start-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); SVGElemRef->attach(SVGElem_uri3); - elemref = NULL; if (elemref = SVGElemRef->getObject()) { elemref->deleteObject(); } Inkscape::URI SVGElem_uri4(((Glib::ustring)"#" + (Glib::ustring)"infoline-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); SVGElemRef->attach(SVGElem_uri4); - elemref = NULL; if (elemref = SVGElemRef->getObject()) { elemref->deleteObject(); } @@ -714,7 +745,7 @@ LPEMeasureLine::saveDefault() prefs->setDouble("/live_effects/measure-line/scale", scale); prefs->setInt("/live_effects/measure-line/precision", precision); prefs->setDouble("/live_effects/measure-line/position", position); - prefs->setDouble("/live_effects/measure-line/text_distance", text_distance); + prefs->setDouble("/live_effects/measure-line/text_top_bottom", text_top_bottom); prefs->setDouble("/live_effects/measure-line/helpline_distance", helpline_distance); prefs->setDouble("/live_effects/measure-line/helpline_overlap", helpline_overlap); prefs->setString("/live_effects/measure-line/unit", (Glib::ustring)unit.get_abbreviation()); @@ -728,6 +759,7 @@ LPEMeasureLine::saveDefault() prefs->setBool("/live_effects/measure-line/local_locale", local_locale); prefs->setBool("/live_effects/measure-line/line_group_05", line_group_05); prefs->setBool("/live_effects/measure-line/rotate_anotation", rotate_anotation); + prefs->setBool("/live_effects/measure-line/hide_back", hide_back); } }; //namespace LivePathEffect diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index 7e9bfabc7..7819a94d7 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -42,7 +42,7 @@ public: virtual void doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/); virtual Geom::PathVector doEffect_path(Geom::PathVector const &path_in); void createLine(Geom::Point start,Geom::Point end,Glib::ustring id, bool main, bool remove); - void createTextLabel(Geom::Point pos, double length, Geom::Coord angle, double fontsize, bool remove); + void createTextLabel(Geom::Point pos, double length, Geom::Coord angle, bool remove); void onExpanderChanged(); void createArrowMarker(Glib::ustring mode); void saveDefault(); @@ -54,7 +54,8 @@ private: ScalarParam curve_linked; ScalarParam precision; ScalarParam position; - ScalarParam text_distance; + ScalarParam text_top_bottom; + ScalarParam text_right_left; ScalarParam helpline_distance; ScalarParam helpline_overlap; ScalarParam scale; @@ -65,6 +66,7 @@ private: BoolParam local_locale; BoolParam line_group_05; BoolParam rotate_anotation; + BoolParam hide_back; TextParam dimline_format; TextParam helperlines_format; TextParam anotation_format; @@ -73,6 +75,9 @@ private: bool expanded; Gtk::Expander * expander; double doc_scale; + double fontsize; + double anotation_width; + double arrow_gap; /* Geom::Affine affine_over;*/ LPEMeasureLine(const LPEMeasureLine &); LPEMeasureLine &operator=(const LPEMeasureLine &); -- cgit v1.2.3 From af36c60d5f160f314640b6402769779e18d9b2ef Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 2 Aug 2016 13:41:58 +0200 Subject: Add houz improvement text right/left with line out (bzr r15017.1.33) --- src/live_effects/lpe-measure-line.cpp | 62 ++++++++++++++++++++++++++++++----- src/live_effects/lpe-measure-line.h | 2 +- 2 files changed, 54 insertions(+), 10 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 393961a13..04085015c 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -218,6 +218,16 @@ LPEMeasureLine::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) node->setAttribute("style", NULL); } } + Inkscape::URI SVGElem_uri5(((Glib::ustring)"#" + (Glib::ustring)"downline-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + SVGElemRef->attach(SVGElem_uri5); + if (elemref = SVGElemRef->getObject()) { + node = elemref->getRepr(); + if (!this->isVisible()) { + node->setAttribute("style", "display:none"); + } else { + node->setAttribute("style", NULL); + } + } } } @@ -305,6 +315,7 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl SVGElemRef->attach(SVGElem_uri); SPObject *elemref = NULL; Inkscape::XML::Node *rtspan = NULL; + pos = pos - Point::polar(angle, text_right_left); if (elemref = SVGElemRef->getObject()) { if (remove) { elemref->deleteObject(); @@ -404,7 +415,7 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl Inkscape::GC::release(rtext); } Inkscape::XML::Node *tmp_node = rtext->duplicate(xml_doc); - affine = Geom::Affine(Geom::Scale(1.1)); + affine = Geom::Affine(Geom::Scale(1.4)); tmp_node->setAttribute("transform", sp_svg_transform_write(affine)); SPObject * tmp_obj = SP_OBJECT(desktop->currentLayer()->appendChildRepr(tmp_node)); Inkscape::GC::release(tmp_node); @@ -418,7 +429,7 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl } void -LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, bool main, bool remove) +LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, bool main, bool overflow, bool remove, bool arrows) { if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); @@ -434,7 +445,7 @@ LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, end = end + Point::polar(angle, helpline_overlap ); } Geom::PathVector line_pathv; - if (main && std::abs(text_top_bottom) < fontsize/1.5 && hide_back){ + if (main && std::abs(text_top_bottom) < fontsize/1.5 && hide_back && !overflow){ Geom::Path line_path; double k = 0; if (flip_side) { @@ -478,7 +489,9 @@ LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, line->setAttribute("d" , line_str); } Glib::ustring style = (Glib::ustring)"stroke:#000000;fill:none;"; - if (main) { + if (overflow && !arrows) { + line->setAttribute("inkscape:label", "downline"); + } else if (main) { line->setAttribute("inkscape:label", "dinline"); if (arrows_outside) { style = style + (Glib::ustring)"marker-start:url(#ArrowDINout-start);marker-end:url(#ArrowDINout-end);"; @@ -605,6 +618,34 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) length *= (affinetransform.expansionX() + affinetransform.expansionY()) / 2.0; } createTextLabel(pos, length, angle, remove); + bool overflow = false; + if ((anotation_width/2) + std::abs(text_right_left) > Geom::distance(start,end)/2.0) { + Geom::Point sstart = end - Point::polar(angle_cross, position); + Geom::Point send = end - Point::polar(angle_cross, position); + if (text_right_left < 0 && flip_side || text_right_left > 0 && !flip_side) { + sstart = start - Point::polar(angle_cross, position); + send = start - Point::polar(angle_cross, position); + } + Geom::Point prog_end = Geom::Point(); + if (std::abs(text_top_bottom) < fontsize/1.5 && hide_back) { + if (text_right_left > 0 ) { + prog_end = sstart - Point::polar(angle, std::abs(text_right_left) - (anotation_width/1.9) - (Geom::distance(start,end)/2.0)); + } else { + prog_end = sstart + Point::polar(angle, std::abs(text_right_left) - (anotation_width/1.9) - (Geom::distance(start,end)/2.0)); + } + } else { + if (text_right_left > 0 ) { + prog_end = sstart - Point::polar(angle,(anotation_width/2) + std::abs(text_right_left) - (Geom::distance(start,end)/2.0)); + } else { + prog_end = sstart + Point::polar(angle,(anotation_width/2) + std::abs(text_right_left) - (Geom::distance(start,end)/2.0)); + } + } + overflow = true; + createLine(sstart, prog_end, (Glib::ustring)"downline-" + (Glib::ustring)this->getRepr()->attribute("id"), true, overflow, false, false); + } else { + //erase it + createLine(Geom::Point(),Geom::Point(), (Glib::ustring)"downline-" + (Glib::ustring)this->getRepr()->attribute("id"), true, overflow, true, false); + } //LINE arrow_gap = 8 * Inkscape::Util::Quantity::convert(0.35 / doc_scale, "mm", display_unit.c_str()); if (line_group_05) { @@ -621,20 +662,18 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) if (flip_side) { arrow_gap *= -1; } - angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); - if (angle_cross < 0) angle_cross += 2*M_PI; hstart = hstart - Point::polar(angle_cross, position); Glib::ustring id = (Glib::ustring)"infoline-on-start-" + (Glib::ustring)this->getRepr()->attribute("id"); - createLine(start, hstart, id, false, remove); + createLine(start, hstart, id, false, false, remove); hend = hend - Point::polar(angle_cross, position); id = (Glib::ustring)"infoline-on-end-" + (Glib::ustring)this->getRepr()->attribute("id"); - createLine(end, hend, id, false, remove); + createLine(end, hend, id, false, false, remove); if (!arrows_outside) { hstart = hstart + Point::polar(angle, arrow_gap); hend = hend - Point::polar(angle, arrow_gap ); } id = (Glib::ustring)"infoline-" + (Glib::ustring)this->getRepr()->attribute("id"); - createLine(hstart, hend, id, true, remove); + createLine(hstart, hend, id, true, overflow, remove, true); } } } @@ -665,6 +704,11 @@ void LPEMeasureLine::doOnRemove (SPLPEItem const* lpeitem) if (elemref = SVGElemRef->getObject()) { elemref->deleteObject(); } + Inkscape::URI SVGElem_uri5(((Glib::ustring)"#" + (Glib::ustring)"downline-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + SVGElemRef->attach(SVGElem_uri5); + if (elemref = SVGElemRef->getObject()) { + elemref->deleteObject(); + } } } diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index 7819a94d7..f9c925ef3 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -41,7 +41,7 @@ public: virtual void doOnRemove (SPLPEItem const* lpeitem); virtual void doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/); virtual Geom::PathVector doEffect_path(Geom::PathVector const &path_in); - void createLine(Geom::Point start,Geom::Point end,Glib::ustring id, bool main, bool remove); + void createLine(Geom::Point start,Geom::Point end,Glib::ustring id, bool main, bool overflow, bool remove, bool arrows = false); void createTextLabel(Geom::Point pos, double length, Geom::Coord angle, bool remove); void onExpanderChanged(); void createArrowMarker(Glib::ustring mode); -- cgit v1.2.3 From 67fa2b7c2a26e909b1adb5fb188285367dfba7e4 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 3 Oct 2016 23:35:23 +0200 Subject: Fix merge bugs (bzr r15017.1.36) --- src/live_effects/lpe-measure-line.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 04085015c..6e77931b0 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -161,6 +161,11 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : LPEMeasureLine::~LPEMeasureLine() {} +void swap(Geom::Point &A, Geom::Point &B){ + Geom::Point tmp = A; + A = B; + B = tmp; +} void LPEMeasureLine::doOnApply(SPLPEItem const* lpeitem) { -- cgit v1.2.3 From 5a0f38c94489c344e66b0a4441668ea02e3361d8 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 4 Oct 2016 17:32:38 +0200 Subject: Fix scaling bug (bzr r15017.1.37) --- src/live_effects/lpe-measure-line.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 6e77931b0..57e67ab3a 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -541,6 +541,9 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) SPPath *sp_path = dynamic_cast(splpeitem); if (sp_path) { Geom::PathVector pathvector = sp_path->get_original_curve()->get_pathvector(); + SPDocument * doc = SP_ACTIVE_DOCUMENT; + Geom::Affine affinetransform = i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(doc->getRoot())); + pathvector *= affinetransform; if (arrows_outside) { createArrowMarker((Glib::ustring)"ArrowDINout-start"); createArrowMarker((Glib::ustring)"ArrowDINout-end"); @@ -618,9 +621,8 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } else { pos = pos - Point::polar(angle_cross, (position + text_top_bottom) - fontsize/2.5); } - if (!scale_insensitive) { - Geom::Affine affinetransform = i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(desktop->doc()->getRoot())); - length *= (affinetransform.expansionX() + affinetransform.expansionY()) / 2.0; + if (scale_insensitive) { + length *= (affinetransform.inverse().expansionX() + affinetransform.inverse().expansionY()) / 2.0; } createTextLabel(pos, length, angle, remove); bool overflow = false; -- cgit v1.2.3 From 98f6a39975eef4b0d711e13b6743e494347d8ae0 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 5 Oct 2016 00:08:23 +0200 Subject: add lock (bzr r15017.1.39) --- src/live_effects/lpe-measure-line.cpp | 62 +++++++++++++++-------------------- src/live_effects/lpe-measure-line.h | 2 +- 2 files changed, 28 insertions(+), 36 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 4780fb817..434dc484c 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -67,7 +67,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : line_group_05(_("Line Group 0.5*"), _("Line Group 0.5, from 0.7"), "line_group_05", &wr, this, true), rotate_anotation(_("Rotate Anotation*"), _("Rotate Anotation"), "rotate_anotation", &wr, this, true), hide_back(_("Hide if label over*"), _("Hide DIN line if label over"), "hide_back", &wr, this, true), - lock_measure(_("Lock measure data"), _("Lock measure data to avoid problems on transforms"), "lock_measure", &wr, this, true), + unlock_measure(_("Unlock measure data"), _("Unlock measure data maybe give problems on transforms"), "unlock_measure", &wr, this, false), dimline_format(_("CSS DIN line*"), _("Override CSS to DIN line, return to save, empty to reset to DIM"), "dimline_format", &wr, this,""), helperlines_format(_("CSS helpers*"), _("Override CSS to helper lines, return to save, empty to reset to DIM"), "helperlines_format", &wr, this,""), anotation_format(_("CSS anotation*"), _("Override CSS to anotation text, return to save, empty to reset to DIM"), "anotation_format", &wr, this,""), @@ -93,7 +93,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : registerParameter(&line_group_05); registerParameter(&rotate_anotation); registerParameter(&hide_back); - registerParameter(&lock_measure); + registerParameter(&unlock_measure); registerParameter(&dimline_format); registerParameter(&helperlines_format); registerParameter(&anotation_format); @@ -256,10 +256,10 @@ LPEMeasureLine::createArrowMarker(Glib::ustring mode) arrow->setAttribute("refX", "0.0"); arrow->setAttribute("refY", "0.0"); arrow->setAttribute("style", "overflow:visible"); - if (lock_measure) { - arrow->setAttribute("sodipodi:insensitive", "true"); - } else { + if (unlock_measure) { arrow->setAttribute("sodipodi:insensitive", NULL); + } else { + arrow->setAttribute("sodipodi:insensitive", "true"); } /* Create */ Inkscape::XML::Node *arrow_path = xml_doc->createElement("svg:path"); @@ -288,10 +288,10 @@ LPEMeasureLine::createArrowMarker(Glib::ustring mode) } else { Inkscape::XML::Node *arrow= elemref->getRepr(); if (arrow) { - if (lock_measure) { - arrow->setAttribute("sodipodi:insensitive", "true"); - } else { + if (unlock_measure) { arrow->setAttribute("sodipodi:insensitive", NULL); + } else { + arrow->setAttribute("sodipodi:insensitive", "true"); } Inkscape::XML::Node *arrow_data = arrow->firstChild(); if (arrow_data) { @@ -339,16 +339,14 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl elemref->deleteObject(); return; } -// Geom::Affine affinetransform = i2anc_affine(SP_OBJECT(elemref)->parent, SP_OBJECT(desktop->doc()->getRoot())); -// pos *= affinetransform; pos = pos - Point::polar(angle, text_right_left); rtext = elemref->getRepr(); sp_repr_set_svg_double(rtext, "x", pos[Geom::X]); sp_repr_set_svg_double(rtext, "y", pos[Geom::Y]); - if (lock_measure) { - rtext->setAttribute("sodipodi:insensitive", "true"); - } else { + if (unlock_measure) { rtext->setAttribute("sodipodi:insensitive", NULL); + } else { + rtext->setAttribute("sodipodi:insensitive", "true"); } } else { if (remove) { @@ -357,10 +355,10 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl rtext = xml_doc->createElement("svg:text"); rtext->setAttribute("xml:space", "preserve"); rtext->setAttribute("id", ( (Glib::ustring)"text-on-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); - if (lock_measure) { - rtext->setAttribute("sodipodi:insensitive", "true"); - } else { + if (unlock_measure) { rtext->setAttribute("sodipodi:insensitive", NULL); + } else { + rtext->setAttribute("sodipodi:insensitive", "true"); } pos = pos - Point::polar(angle, text_right_left); sp_repr_set_svg_double(rtext, "x", pos[Geom::X]); @@ -477,11 +475,7 @@ LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, end = end + Point::polar(angle, helpline_overlap ); } Geom::PathVector line_pathv; - SPDocument * doc = SP_ACTIVE_DOCUMENT; - Geom::Affine affinetransform = i2anc_affine(SP_OBJECT(sp_lpe_item)->parent, SP_OBJECT(doc->getRoot())); - double parents_scale = (affinetransform.inverse().expansionX() + affinetransform.inverse().expansionY()) / 2.0; - double current_text_top_bottom = text_top_bottom / parents_scale; - if (main && std::abs(current_text_top_bottom) < fontsize/1.5 && hide_back && !overflow){ + if (main && std::abs(text_top_bottom) < fontsize/1.5 && hide_back && !overflow){ Geom::Path line_path; double k = 0; if (flip_side) { @@ -526,10 +520,10 @@ LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, gchar * line_str = sp_svg_write_path( line_pathv ); line->setAttribute("d" , line_str); } - if (lock_measure) { - line->setAttribute("sodipodi:insensitive", "true"); - } else { + if (unlock_measure) { line->setAttribute("sodipodi:insensitive", NULL); + } else { + line->setAttribute("sodipodi:insensitive", "true"); } line_pathv.clear(); @@ -583,8 +577,6 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) SPDocument * doc = SP_ACTIVE_DOCUMENT; Geom::Affine affinetransform = i2anc_affine(SP_OBJECT(lpeitem)->parent, SP_OBJECT(doc->getRoot())); double parents_scale = (affinetransform.inverse().expansionX() + affinetransform.inverse().expansionY()) / 2.0; - double current_text_top_bottom = text_top_bottom / parents_scale; - double current_position = position / parents_scale; Geom::PathVector pathvector = sp_path->get_original_curve()->get_pathvector(); pathvector *= affinetransform; @@ -661,9 +653,9 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) angle = std::fmod(angle, 2*M_PI); if (angle < 0) angle += 2*M_PI; if (angle >= rad_from_deg(90) && angle < rad_from_deg(270)) { - pos = pos - Point::polar(angle_cross, (current_position - current_text_top_bottom) + fontsize/2.5); + pos = pos - Point::polar(angle_cross, (position - text_top_bottom) + fontsize/2.5); } else { - pos = pos - Point::polar(angle_cross, (current_position + current_text_top_bottom) - fontsize/2.5); + pos = pos - Point::polar(angle_cross, (position + text_top_bottom) - fontsize/2.5); } if (scale_insensitive) { length *= parents_scale; @@ -671,14 +663,14 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) createTextLabel(pos, length, angle, remove); bool overflow = false; if ((anotation_width/2) + std::abs(text_right_left) > Geom::distance(start,end)/2.0) { - Geom::Point sstart = end - Point::polar(angle_cross, current_position); - Geom::Point send = end - Point::polar(angle_cross, current_position); + Geom::Point sstart = end - Point::polar(angle_cross, position); + Geom::Point send = end - Point::polar(angle_cross, position); if (text_right_left < 0 && flip_side || text_right_left > 0 && !flip_side) { - sstart = start - Point::polar(angle_cross, current_position); - send = start - Point::polar(angle_cross, current_position); + sstart = start - Point::polar(angle_cross, position); + send = start - Point::polar(angle_cross, position); } Geom::Point prog_end = Geom::Point(); - if (std::abs(current_text_top_bottom) < fontsize/1.5 && hide_back) { + if (std::abs(text_top_bottom) < fontsize/1.5 && hide_back) { if (text_right_left > 0 ) { prog_end = sstart - Point::polar(angle, std::abs(text_right_left) - (anotation_width/1.9) - (Geom::distance(start,end)/2.0)); } else { @@ -713,10 +705,10 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) if (flip_side) { arrow_gap *= -1; } - hstart = hstart - Point::polar(angle_cross, current_position); + hstart = hstart - Point::polar(angle_cross, position); Glib::ustring id = (Glib::ustring)"infoline-on-start-" + (Glib::ustring)this->getRepr()->attribute("id"); createLine(start, hstart, id, false, false, remove); - hend = hend - Point::polar(angle_cross, current_position); + hend = hend - Point::polar(angle_cross, position); id = (Glib::ustring)"infoline-on-end-" + (Glib::ustring)this->getRepr()->attribute("id"); createLine(end, hend, id, false, false, remove); if (!arrows_outside) { diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index 83fef26b8..999d53af0 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -67,7 +67,7 @@ private: BoolParam line_group_05; BoolParam rotate_anotation; BoolParam hide_back; - BoolParam lock_measure; + BoolParam unlock_measure; TextParam dimline_format; TextParam helperlines_format; TextParam anotation_format; -- cgit v1.2.3 From 124c2b96d76984dd9fe7a4db0f9b8738ea3ba657 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 5 Oct 2016 18:51:40 +0200 Subject: add button to release measures (bzr r15017.1.40) --- src/live_effects/lpe-measure-line.cpp | 85 +++++++++++++++++++++++------------ src/live_effects/lpe-measure-line.h | 3 +- src/live_effects/lpeobject.h | 10 ++++- 3 files changed, 67 insertions(+), 31 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 434dc484c..e8ceb7e51 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -10,6 +10,7 @@ */ #include "live_effects/lpe-measure-line.h" #include +#include "ui/dialog/livepatheffect-editor.h" #include #include "inkscape.h" #include "xml/node.h" @@ -21,7 +22,7 @@ #include "svg/svg-color.h" #include "svg/svg.h" #include "display/curve.h" -#include <2geom/affine.h> +#include "2geom/affine.h" #include "style.h" #include "sp-root.h" #include "sp-defs.h" @@ -67,7 +68,6 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : line_group_05(_("Line Group 0.5*"), _("Line Group 0.5, from 0.7"), "line_group_05", &wr, this, true), rotate_anotation(_("Rotate Anotation*"), _("Rotate Anotation"), "rotate_anotation", &wr, this, true), hide_back(_("Hide if label over*"), _("Hide DIN line if label over"), "hide_back", &wr, this, true), - unlock_measure(_("Unlock measure data"), _("Unlock measure data maybe give problems on transforms"), "unlock_measure", &wr, this, false), dimline_format(_("CSS DIN line*"), _("Override CSS to DIN line, return to save, empty to reset to DIM"), "dimline_format", &wr, this,""), helperlines_format(_("CSS helpers*"), _("Override CSS to helper lines, return to save, empty to reset to DIM"), "helperlines_format", &wr, this,""), anotation_format(_("CSS anotation*"), _("Override CSS to anotation text, return to save, empty to reset to DIM"), "anotation_format", &wr, this,""), @@ -93,7 +93,6 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : registerParameter(&line_group_05); registerParameter(&rotate_anotation); registerParameter(&hide_back); - registerParameter(&unlock_measure); registerParameter(&dimline_format); registerParameter(&helperlines_format); registerParameter(&anotation_format); @@ -159,6 +158,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : helpline_overlap.param_set_range(-999999.0, 999999.0); helpline_overlap.param_set_increments(1, 1); helpline_overlap.param_set_digits(2); + erase = true; } LPEMeasureLine::~LPEMeasureLine() {} @@ -256,11 +256,7 @@ LPEMeasureLine::createArrowMarker(Glib::ustring mode) arrow->setAttribute("refX", "0.0"); arrow->setAttribute("refY", "0.0"); arrow->setAttribute("style", "overflow:visible"); - if (unlock_measure) { - arrow->setAttribute("sodipodi:insensitive", NULL); - } else { - arrow->setAttribute("sodipodi:insensitive", "true"); - } + arrow->setAttribute("sodipodi:insensitive", "true"); /* Create */ Inkscape::XML::Node *arrow_path = xml_doc->createElement("svg:path"); if (mode == (Glib::ustring)"ArrowDIN-start") { @@ -288,11 +284,7 @@ LPEMeasureLine::createArrowMarker(Glib::ustring mode) } else { Inkscape::XML::Node *arrow= elemref->getRepr(); if (arrow) { - if (unlock_measure) { - arrow->setAttribute("sodipodi:insensitive", NULL); - } else { - arrow->setAttribute("sodipodi:insensitive", "true"); - } + arrow->setAttribute("sodipodi:insensitive", "true"); Inkscape::XML::Node *arrow_data = arrow->firstChild(); if (arrow_data) { SPCSSAttr *css = sp_repr_css_attr_new(); @@ -343,11 +335,7 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl rtext = elemref->getRepr(); sp_repr_set_svg_double(rtext, "x", pos[Geom::X]); sp_repr_set_svg_double(rtext, "y", pos[Geom::Y]); - if (unlock_measure) { - rtext->setAttribute("sodipodi:insensitive", NULL); - } else { - rtext->setAttribute("sodipodi:insensitive", "true"); - } + rtext->setAttribute("sodipodi:insensitive", "true"); } else { if (remove) { return; @@ -355,11 +343,7 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl rtext = xml_doc->createElement("svg:text"); rtext->setAttribute("xml:space", "preserve"); rtext->setAttribute("id", ( (Glib::ustring)"text-on-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); - if (unlock_measure) { - rtext->setAttribute("sodipodi:insensitive", NULL); - } else { - rtext->setAttribute("sodipodi:insensitive", "true"); - } + rtext->setAttribute("sodipodi:insensitive", "true"); pos = pos - Point::polar(angle, text_right_left); sp_repr_set_svg_double(rtext, "x", pos[Geom::X]); sp_repr_set_svg_double(rtext, "y", pos[Geom::Y]); @@ -520,11 +504,7 @@ LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, gchar * line_str = sp_svg_write_path( line_pathv ); line->setAttribute("d" , line_str); } - if (unlock_measure) { - line->setAttribute("sodipodi:insensitive", NULL); - } else { - line->setAttribute("sodipodi:insensitive", "true"); - } + line->setAttribute("sodipodi:insensitive", "true"); line_pathv.clear(); Glib::ustring style = (Glib::ustring)"stroke:#000000;fill:none;"; @@ -723,6 +703,8 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) void LPEMeasureLine::doOnRemove (SPLPEItem const* lpeitem) { + if (!erase) return; + if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)"text-on-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); @@ -754,6 +736,48 @@ void LPEMeasureLine::doOnRemove (SPLPEItem const* lpeitem) } } +void LPEMeasureLine::toObjects() +{ + if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { + + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)"text-on-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + if (elemref = SVGElemRef->getObject()) { + elemref->getRepr()->setAttribute("sodipodi:insensitive", NULL); + } + Inkscape::URI SVGElem_uri2(((Glib::ustring)"#" + (Glib::ustring)"infoline-on-end-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + SVGElemRef->attach(SVGElem_uri2); + if (elemref = SVGElemRef->getObject()) { + elemref->getRepr()->setAttribute("sodipodi:insensitive", NULL); + } + Inkscape::URI SVGElem_uri3(((Glib::ustring)"#" + (Glib::ustring)"infoline-on-start-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + SVGElemRef->attach(SVGElem_uri3); + if (elemref = SVGElemRef->getObject()) { + elemref->getRepr()->setAttribute("sodipodi:insensitive", NULL); + } + Inkscape::URI SVGElem_uri4(((Glib::ustring)"#" + (Glib::ustring)"infoline-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + SVGElemRef->attach(SVGElem_uri4); + if (elemref = SVGElemRef->getObject()) { + elemref->getRepr()->setAttribute("sodipodi:insensitive", NULL); + } + Inkscape::URI SVGElem_uri5(((Glib::ustring)"#" + (Glib::ustring)"downline-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + SVGElemRef->attach(SVGElem_uri5); + if (elemref = SVGElemRef->getObject()) { + elemref->getRepr()->setAttribute("sodipodi:insensitive", NULL); + } + erase = false; + sp_lpe_item->removeCurrentPathEffect(true); + //TODO: find better way to refresh effect list + if (SP_IS_OBJECT(sp_lpe_item)){ + Inkscape::Selection *selection = SP_ACTIVE_DESKTOP->getSelection(); + selection->remove(SP_OBJECT(sp_lpe_item)); + selection->add(SP_OBJECT(sp_lpe_item)); + } + } +} + Gtk::Widget *LPEMeasureLine::newWidget() { // use manage here, because after deletion of Effect object, others might @@ -766,6 +790,7 @@ Gtk::Widget *LPEMeasureLine::newWidget() std::vector::iterator it = param_vector.begin(); Gtk::HBox * button1 = Gtk::manage(new Gtk::HBox(true,0)); + Gtk::HBox * button2 = Gtk::manage(new Gtk::HBox(true,0)); Gtk::VBox * vbox_expander = Gtk::manage( new Gtk::VBox(Effect::newWidget()) ); vbox_expander->set_border_width(0); vbox_expander->set_spacing(2); @@ -797,12 +822,16 @@ Gtk::Widget *LPEMeasureLine::newWidget() Gtk::Button *save_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Save '*' as default")))); save_default->signal_clicked().connect(sigc::mem_fun(*this, &LPEMeasureLine::saveDefault)); button1->pack_start(*save_default, true, true, 2); + Gtk::Button *remove = Gtk::manage(new Gtk::Button(Glib::ustring(_("Convert to objects")))); + remove->signal_clicked().connect(sigc::mem_fun(*this, &LPEMeasureLine::toObjects)); + button2->pack_start(*remove, true, true, 2); expander = Gtk::manage(new Gtk::Expander(Glib::ustring(_("Show DIM CSS style override")))); expander->add(*vbox_expander); expander->set_expanded(expanded); expander->property_expanded().signal_changed().connect(sigc::mem_fun(*this, &LPEMeasureLine::onExpanderChanged) ); vbox->pack_start(*expander, true, true, 2); vbox->pack_start(*button1, true, true, 2); + vbox->pack_start(*button2, true, true, 2); return dynamic_cast(vbox); } diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index 999d53af0..2fab9dbb9 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -44,6 +44,7 @@ public: void createLine(Geom::Point start,Geom::Point end,Glib::ustring id, bool main, bool overflow, bool remove, bool arrows = false); void createTextLabel(Geom::Point pos, double length, Geom::Coord angle, bool remove); void onExpanderChanged(); + void toObjects(); void createArrowMarker(Glib::ustring mode); void saveDefault(); virtual Gtk::Widget *newWidget(); @@ -67,7 +68,6 @@ private: BoolParam line_group_05; BoolParam rotate_anotation; BoolParam hide_back; - BoolParam unlock_measure; TextParam dimline_format; TextParam helperlines_format; TextParam anotation_format; @@ -79,6 +79,7 @@ private: double fontsize; double anotation_width; double arrow_gap; + bool erase; /* Geom::Affine affine_over;*/ LPEMeasureLine(const LPEMeasureLine &); LPEMeasureLine &operator=(const LPEMeasureLine &); diff --git a/src/live_effects/lpeobject.h b/src/live_effects/lpeobject.h index 2e62707e3..087223947 100644 --- a/src/live_effects/lpeobject.h +++ b/src/live_effects/lpeobject.h @@ -38,8 +38,14 @@ public: /* Note that the returned pointer can be NULL in a valid LivePathEffectObject contained in a valid list of lpeobjects in an lpeitem! * So one should always check whether the returned value is NULL or not */ - Inkscape::LivePathEffect::Effect * get_lpe() { return lpe; }; - Inkscape::LivePathEffect::Effect const * get_lpe() const { return lpe; }; + Inkscape::LivePathEffect::Effect * get_lpe() { + if(this) return lpe; + else return NULL; + } + Inkscape::LivePathEffect::Effect const * get_lpe() const { + if(this) return lpe; + else return NULL; + }; Inkscape::LivePathEffect::Effect *lpe; // this can be NULL in a valid LivePathEffectObject -- cgit v1.2.3 From e64d416e42f8361036d9a31dff5b646810f69e97 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 8 Oct 2016 02:03:08 +0200 Subject: Fix bug:1622321 on powerstroke Fixed bugs: - https://launchpad.net/bugs/1622321 (bzr r15154) --- src/live_effects/lpe-powerstroke.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-powerstroke.cpp b/src/live_effects/lpe-powerstroke.cpp index 0de668847..329a00756 100644 --- a/src/live_effects/lpe-powerstroke.cpp +++ b/src/live_effects/lpe-powerstroke.cpp @@ -609,11 +609,12 @@ LPEPowerStroke::doEffect_path (Geom::PathVector const & path_in) // find time values for which x lies outside path domain // and only take portion of x and y that lies within those time values std::vector< double > rtsmin = roots (x - pwd2_in.domain().min()); - std::vector< double > rtsmax = roots (x - pwd2_in.domain().max()); + std::vector< double > rtsmax = roots (x + pwd2_in.domain().max()); if ( !rtsmin.empty() && !rtsmax.empty() ) { x = portion(x, rtsmin.at(0), rtsmax.at(0)); y = portion(y, rtsmin.at(0), rtsmax.at(0)); } + LineJoinType jointype = static_cast(linejoin_type.get_value()); Piecewise > pwd2_out = compose(pwd2_in,x) + y*compose(n,x); -- cgit v1.2.3