summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2016-07-21 19:05:55 +0000
committerjabiertxof <info@marker.es>2016-07-21 19:05:55 +0000
commite7afb49bd67284227bf5df1df22f9993b1bfa581 (patch)
tree5ee0f0a2edaa66685ffa97d1150978317b360f39 /src
parentDisambiguate sigc::ptr_fun to fix C++14 compilation. (diff)
downloadinkscape-e7afb49bd67284227bf5df1df22f9993b1bfa581.tar.gz
inkscape-e7afb49bd67284227bf5df1df22f9993b1bfa581.zip
This for you CR ยท Measure line, show the distance on rect lines CAD like with auto update
(bzr r15017.1.1)
Diffstat (limited to 'src')
-rw-r--r--src/live_effects/CMakeLists.txt4
-rw-r--r--src/live_effects/Makefile_insert2
-rw-r--r--src/live_effects/effect-enum.h1
-rw-r--r--src/live_effects/effect.cpp6
-rw-r--r--src/live_effects/lpe-measure-line.cpp45
-rw-r--r--src/live_effects/lpe-measure-line.h48
-rw-r--r--src/live_effects/parameter/texttopath.cpp125
-rw-r--r--src/live_effects/parameter/texttopath.h87
8 files changed, 318 insertions, 0 deletions
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<EffectType> 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<EffectType> LPETypeConverter(LPETypeData, sizeof(LPETypeData)/sizeof(*LPETypeData));
@@ -319,6 +322,9 @@ Effect::New(EffectType lpenr, LivePathEffectObject *lpeobj)
case TRANSFORM_2PTS:
neweffect = static_cast<Effect*> ( new LPETransform2Pts(lpeobj) );
break;
+ case MEASURE_LINE:
+ neweffect = static_cast<Effect*> ( 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 <jabier.arraiza@marker.es>
+ *
+ * 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 <glibmm/i18n.h>
+
+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 <jabier.arraiza@marker.es>
+ *
+ * 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 <maximilian.albert@gmail.com>
+ *
+ * Authors:
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#include "ui/widget/registered-widget.h"
+#include <glibmm/i18n.h>
+
+#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<Geom::D2<Geom::SBasis> > &pwd2,
+ const double t, const double length, bool /*use_curvature*/)
+{
+ using namespace Geom;
+
+ Piecewise<D2<SBasis> > 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<Gtk::Widget *> (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 <glib.h>
+
+#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<Geom::D2<Geom::SBasis> > &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 :