summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2016-07-24 23:43:33 +0000
committerjabiertxof <info@marker.es>2016-07-24 23:43:33 +0000
commit10790202dbd81463005cc3ae7cdb6f2068003adb (patch)
tree2d880d6a61dfaede7643366f5615f192fd9d5a84 /src
parentFix a var name bug (diff)
downloadinkscape-10790202dbd81463005cc3ae7cdb6f2068003adb.tar.gz
inkscape-10790202dbd81463005cc3ae7cdb6f2068003adb.zip
Add strore parameters
(bzr r15017.1.5)
Diffstat (limited to 'src')
-rw-r--r--src/live_effects/lpe-measure-line.cpp265
-rw-r--r--src/live_effects/lpe-measure-line.h18
-rw-r--r--src/live_effects/parameter/bool.cpp6
-rw-r--r--src/live_effects/parameter/bool.h2
-rw-r--r--src/live_effects/parameter/font.cpp7
-rw-r--r--src/live_effects/parameter/font.h1
-rw-r--r--src/live_effects/parameter/parameter.cpp7
-rw-r--r--src/live_effects/parameter/parameter.h1
-rw-r--r--src/live_effects/parameter/point.cpp4
-rw-r--r--src/live_effects/parameter/point.h2
-rw-r--r--src/live_effects/parameter/unit.cpp6
-rw-r--r--src/live_effects/parameter/unit.h1
12 files changed, 239 insertions, 81 deletions
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<SPLPEItem*>(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 <tspan> */
- rtspan = xml_doc->createElement("svg:tspan");
- rtspan->setAttribute("sodipodi:role", "line");
+ SPLPEItem * splpeitem = const_cast<SPLPEItem *>(lpeitem);
+ SPPath *sp_path = dynamic_cast<SPPath *>(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 <tspan> */
+ 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<Parameter *>::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<Gtk::Widget *>(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<Gtk::Widget *>(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<Geom::LineSegment>( 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 <libnrtype/font-lister.h>
+#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<Gtk::Widget *> (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<Gtk::Widget *> (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();