diff options
| author | Jabiertxof <jtx@jtx> | 2016-12-19 21:12:42 +0000 |
|---|---|---|
| committer | Jabiertxof <jtx@jtx> | 2016-12-19 21:12:42 +0000 |
| commit | 2f6848dc2b7ed9c60dcd440d7bf4ed39423636ca (patch) | |
| tree | 155209be74f4ccf92138ec0656176053b6797438 | |
| parent | Update to trunk (diff) | |
| parent | Remove some ocurrences of desktop in knot functions (diff) | |
| download | inkscape-2f6848dc2b7ed9c60dcd440d7bf4ed39423636ca.tar.gz inkscape-2f6848dc2b7ed9c60dcd440d7bf4ed39423636ca.zip | |
Update to trunk
(bzr r15295.1.29)
33 files changed, 632 insertions, 698 deletions
diff --git a/src/knot-holder-entity.cpp b/src/knot-holder-entity.cpp index 95b135be0..8add35d46 100644 --- a/src/knot-holder-entity.cpp +++ b/src/knot-holder-entity.cpp @@ -24,6 +24,7 @@ #include "sp-pattern.h" #include "snap.h" #include "desktop.h" +#include "inkscape.h" #include "sp-namedview.h" int KnotHolderEntity::counter = 0; @@ -32,6 +33,9 @@ void KnotHolderEntity::create(SPDesktop *desktop, SPItem *item, KnotHolder *pare const gchar *tip, SPKnotShapeType shape, SPKnotModeType mode, guint32 color) { + if (!desktop) { + desktop = SP_ACTIVE_DESKTOP; + } knot = new SPKnot(desktop, tip); this->parent_holder = parent; diff --git a/src/knot.cpp b/src/knot.cpp index 8ac84b97b..84b72d780 100644 --- a/src/knot.cpp +++ b/src/knot.cpp @@ -25,8 +25,6 @@ #include "document-undo.h" #include "message-stack.h" #include "message-context.h" -#include "ui/tools-switch.h" -#include "ui/tools/tool-base.h" #include "ui/tools/node-tool.h" #include <gtk/gtk.h> @@ -254,10 +252,7 @@ static int sp_knot_handler(SPCanvasItem */*item*/, GdkEvent *event, SPKnot *knot consumed = TRUE; } } - if (tools_isactive(knot->desktop, TOOLS_NODES)) { - Inkscape::UI::Tools::NodeTool *nt = static_cast<Inkscape::UI::Tools::NodeTool*>(knot->desktop->event_context); - nt->update_helperpath(); - } + Inkscape::UI::Tools::sp_update_helperpath(); break; case GDK_MOTION_NOTIFY: if (grabbed && knot->desktop && knot->desktop->event_context && !knot->desktop->event_context->space_panning) { @@ -290,10 +285,7 @@ static int sp_knot_handler(SPCanvasItem */*item*/, GdkEvent *event, SPKnot *knot sp_knot_handler_request_position(event, knot); moved = TRUE; } - if (tools_isactive(knot->desktop, TOOLS_NODES)) { - Inkscape::UI::Tools::NodeTool *nt = static_cast<Inkscape::UI::Tools::NodeTool*>(knot->desktop->event_context); - nt->update_helperpath(); - } + Inkscape::UI::Tools::sp_update_helperpath(); break; case GDK_ENTER_NOTIFY: knot->setFlag(SP_KNOT_MOUSEOVER, TRUE); diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 41b7d8c2c..5cc0d6f20 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -612,15 +612,15 @@ Effect::registerParameter(Parameter * param) * Add all registered LPE knotholder handles to the knotholder */ void -Effect::addHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) { +Effect::addHandles(KnotHolder *knotholder, SPItem *item) { using namespace Inkscape::LivePathEffect; // add handles provided by the effect itself - addKnotHolderEntities(knotholder, desktop, item); + addKnotHolderEntities(knotholder, item); // add handles provided by the effect's parameters (if any) for (std::vector<Parameter *>::iterator p = param_vector.begin(); p != param_vector.end(); ++p) { - (*p)->addKnotHolderEntities(knotholder, desktop, item); + (*p)->addKnotHolderEntities(knotholder, item); } } @@ -660,14 +660,7 @@ Effect::addCanvasIndicators(SPLPEItem const*/*lpeitem*/, std::vector<Geom::PathV */ void Effect::update_helperpath() { - using namespace Inkscape::UI; - SPDesktop *desktop = SP_ACTIVE_DESKTOP; - if (desktop) { - if (tools_isactive(desktop, TOOLS_NODES)) { - Inkscape::UI::Tools::NodeTool *nt = static_cast<Inkscape::UI::Tools::NodeTool*>(desktop->event_context); - nt->update_helperpath(); - } - } + Inkscape::UI::Tools::sp_update_helperpath(); } /** diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index 28a1a4e8e..bc56c2390 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -106,7 +106,7 @@ public: // /TODO: in view of providesOwnFlashPaths() below, this is somewhat redundant // (but spiro lpe still needs it!) virtual LPEPathFlashType pathFlashType() const { return DEFAULT; } - void addHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); + void addHandles(KnotHolder *knotholder, SPItem *item); std::vector<Geom::PathVector> getCanvasIndicators(SPLPEItem const* lpeitem); void update_helperpath(); @@ -149,7 +149,7 @@ protected: void registerParameter(Parameter * param); Parameter * getNextOncanvasEditableParam(); - virtual void addKnotHolderEntities(KnotHolder * /*knotholder*/, SPDesktop * /*desktop*/, SPItem * /*item*/) {}; + virtual void addKnotHolderEntities(KnotHolder * /*knotholder*/, SPItem * /*item*/) {}; virtual void addCanvasIndicators(SPLPEItem const* lpeitem, std::vector<Geom::PathVector> &hp_vec); diff --git a/src/live_effects/lpe-knot.cpp b/src/live_effects/lpe-knot.cpp index c35da0601..2defecb77 100644 --- a/src/live_effects/lpe-knot.cpp +++ b/src/live_effects/lpe-knot.cpp @@ -20,7 +20,6 @@ #include "knot-holder-entity.h" #include "knotholder.h" -#include <glibmm/i18n.h> #include <gdk/gdk.h> #include <2geom/sbasis-to-bezier.h> @@ -616,10 +615,10 @@ LPEKnot::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector<Geom::Pat hp_vec.push_back(pathv); } -void LPEKnot::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) +void LPEKnot::addKnotHolderEntities(KnotHolder *knotholder, SPItem *item) { KnotHolderEntity *e = new KnotHolderEntityCrossingSwitcher(this); - e->create( desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, + e->create( NULL, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _("Drag to select a crossing, click to flip it") ); knotholder->add(e); }; diff --git a/src/live_effects/lpe-knot.h b/src/live_effects/lpe-knot.h index 95bfaf6e1..ac518b97c 100644 --- a/src/live_effects/lpe-knot.h +++ b/src/live_effects/lpe-knot.h @@ -61,7 +61,7 @@ public: /* the knotholder entity classes must be declared friends */ friend class KnotHolderEntityCrossingSwitcher; - void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); + void addKnotHolderEntities(KnotHolder *knotholder, SPItem *item); protected: virtual void addCanvasIndicators(SPLPEItem const *lpeitem, std::vector<Geom::PathVector> &hp_vec); diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 3feb6ff08..df9a84bf8 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -15,8 +15,6 @@ #include "inkscape.h" #include "xml/node.h" #include "xml/sp-css-attr.h" -#include "uri.h" -#include "uri-references.h" #include "preferences.h" #include "util/units.h" #include "svg/svg-length.h" @@ -32,7 +30,6 @@ #include "sp-item.h" #include "sp-shape.h" #include "sp-path.h" -#include "desktop.h" #include "document.h" #include <iomanip> @@ -173,328 +170,316 @@ LPEMeasureLine::~LPEMeasureLine() {} void LPEMeasureLine::createArrowMarker(const char * mode) { - if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { - Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); - Inkscape::URI SVGElem_uri(Glib::ustring("#").append(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); - arrow->setAttribute("inkscape:stockid", mode); - arrow->setAttribute("orient", "auto"); - arrow->setAttribute("refX", "0.0"); - arrow->setAttribute("refY", "0.0"); - arrow->setAttribute("style", "overflow:visible"); + SPDocument * document = SP_ACTIVE_DOCUMENT; + Inkscape::XML::Document *xml_doc = document->getReprDoc(); + SPObject *elemref = NULL; + Inkscape::XML::Node *arrow = NULL; + if (elemref = document->getObjectById(mode)) { + Inkscape::XML::Node *arrow= elemref->getRepr(); + if (arrow) { arrow->setAttribute("sodipodi:insensitive", "true"); - /* Create <path> */ - Inkscape::XML::Node *arrow_path = xml_doc->createElement("svg:path"); - if (std::strcmp(mode, "ArrowDIN-start") == 0) { - arrow_path->setAttribute("d", "M -8,0 8,-2.11 8,2.11 z"); - } else if (std::strcmp(mode, "ArrowDIN-end") == 0) { - arrow_path->setAttribute("d", "M 8,0 -8,2.11 -8,-2.11 z"); - } else if (std::strcmp(mode, "ArrowDINout-start") == 0) { - 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->setAttribute("transform", NULL); + 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"); + arrow_data->setAttribute("transform", NULL); + 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()); } - - arrow_path->setAttribute("id", Glib::ustring(mode).append("_path").c_str()); - 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); - elemref = SP_OBJECT(desktop->getDocument()->getDefs()->appendChildRepr(arrow)); - Inkscape::GC::release(arrow); + } + } else { + arrow = xml_doc->createElement("svg:marker"); + arrow->setAttribute("id", mode); + arrow->setAttribute("inkscape:stockid", mode); + arrow->setAttribute("orient", "auto"); + arrow->setAttribute("refX", "0.0"); + arrow->setAttribute("refY", "0.0"); + arrow->setAttribute("style", "overflow:visible"); + arrow->setAttribute("sodipodi:insensitive", "true"); + /* Create <path> */ + Inkscape::XML::Node *arrow_path = xml_doc->createElement("svg:path"); + if (std::strcmp(mode, "ArrowDIN-start") == 0) { + arrow_path->setAttribute("d", "M -8,0 8,-2.11 8,2.11 z"); + } else if (std::strcmp(mode, "ArrowDIN-end") == 0) { + arrow_path->setAttribute("d", "M 8,0 -8,2.11 -8,-2.11 z"); + } else if (std::strcmp(mode, "ArrowDINout-start") == 0) { + 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 { - Inkscape::XML::Node *arrow= elemref->getRepr(); - if (arrow) { - arrow->setAttribute("sodipodi:insensitive", "true"); - arrow->setAttribute("transform", NULL); - 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"); - arrow_data->setAttribute("transform", NULL); - 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()); - } - } + 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"); } - elements.push_back(mode); + + arrow_path->setAttribute("id", Glib::ustring(mode).append("_path").c_str()); + 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); + elemref = SP_OBJECT(document->getDefs()->appendChildRepr(arrow)); + Inkscape::GC::release(arrow); } + elements.push_back(mode); } void LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angle, bool remove, bool valid) { - if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { - Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); - Inkscape::XML::Node *rtext = NULL; - double doc_w = desktop->getDocument()->getRoot()->width.value; - 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; - } - const char * id = g_strdup(Glib::ustring("text-on-").append(this->getRepr()->attribute("id")).c_str()); - Inkscape::URI SVGElem_uri(Glib::ustring("#").append(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; - } - 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]); - rtext->setAttribute("sodipodi:insensitive", "true"); - rtext->setAttribute("transform", NULL); - } else { - if (remove) { - return; - } - rtext = xml_doc->createElement("svg:text"); - rtext->setAttribute("xml:space", "preserve"); - rtext->setAttribute("id", id); - 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]); - rtspan = xml_doc->createElement("svg:tspan"); - rtspan->setAttribute("sodipodi:role", "line"); - } - const char * transform; - 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; - } - affine *= Geom::Rotate(angle); - affine *= Geom::Translate(pos); - if (rotate_anotation) { - transform = sp_svg_transform_write(affine); - } else { - transform = NULL; - } - 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, "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(); - } - rtext->setAttribute("style", css_str.c_str()); - rtspan->setAttribute("style", NULL); - rtspan->setAttribute("transform", NULL); - sp_repr_css_attr_unref (css); - if (!elemref) { - rtext->addChild(rtspan, NULL); - Inkscape::GC::release(rtspan); - } - 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); - if (local_locale) { - length_str.imbue(std::locale("")); - } else { - length_str.imbue(std::locale::classic()); - } - length_str << std::fixed << length; - 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()); - } - if ( !valid ) { - label_value = Glib::ustring(_("Non Uniform Scale")); - } - Inkscape::XML::Node *rstring = NULL; - if (!elemref) { - rstring = xml_doc->createTextNode(label_value.c_str()); - rtspan->addChild(rstring, NULL); - Inkscape::GC::release(rstring); - } else { - rstring = rtspan->firstChild(); - rstring->setContent(label_value.c_str()); - } - if (!elemref) { - elemref = sp_lpe_item->parent->appendChildRepr(rtext); - Inkscape::GC::release(rtext); - } else if (elemref->parent != sp_lpe_item->parent) { - Inkscape::XML::Node *old_repr = elemref->getRepr(); - Inkscape::XML::Node *copy = old_repr->duplicate(xml_doc); - SPObject * elemref_copy = sp_lpe_item->parent->appendChildRepr(copy); - Inkscape::GC::release(copy); + SPDocument * document = SP_ACTIVE_DOCUMENT; + Inkscape::XML::Document *xml_doc = document->getReprDoc(); + Inkscape::XML::Node *rtext = NULL; + double doc_w = document->getRoot()->width.value; + Geom::Scale scale = document->getDocumentScale(); + SPNamedView *nv = sp_document_namedview(document, NULL); + 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; + } + const char * id = g_strdup(Glib::ustring("text-on-").append(this->getRepr()->attribute("id")).c_str()); + SPObject *elemref = NULL; + Inkscape::XML::Node *rtspan = NULL; + if (elemref = document->getObjectById(id)) { + if (remove) { elemref->deleteObject(); - copy->setAttribute("id", id); - elemref = elemref_copy; + return; } - elements.push_back(id); - Geom::OptRect bounds = SP_ITEM(elemref)->bounds(SPItem::GEOMETRIC_BBOX); - if (bounds) { - anotation_width = bounds->width() * 1.4; + 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]); + rtext->setAttribute("sodipodi:insensitive", "true"); + rtext->setAttribute("transform", NULL); + } else { + if (remove) { + return; } + rtext = xml_doc->createElement("svg:text"); + rtext->setAttribute("xml:space", "preserve"); + rtext->setAttribute("id", id); + 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]); + rtspan = xml_doc->createElement("svg:tspan"); + rtspan->setAttribute("sodipodi:role", "line"); + } + const char * transform; + 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; + } + affine *= Geom::Rotate(angle); + affine *= Geom::Translate(pos); + if (rotate_anotation) { + transform = sp_svg_transform_write(affine); + } else { + transform = NULL; + } + 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, "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(); + } + rtext->setAttribute("style", css_str.c_str()); + rtspan->setAttribute("style", NULL); + rtspan->setAttribute("transform", NULL); + sp_repr_css_attr_unref (css); + if (!elemref) { + rtext->addChild(rtspan, NULL); + Inkscape::GC::release(rtspan); + } + 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); + if (local_locale) { + length_str.imbue(std::locale("")); + } else { + length_str.imbue(std::locale::classic()); + } + length_str << std::fixed << length; + 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()); + } + if ( !valid ) { + label_value = Glib::ustring(_("Non Uniform Scale")); + } + Inkscape::XML::Node *rstring = NULL; + if (!elemref) { + rstring = xml_doc->createTextNode(label_value.c_str()); + rtspan->addChild(rstring, NULL); + Inkscape::GC::release(rstring); + } else { + rstring = rtspan->firstChild(); + rstring->setContent(label_value.c_str()); + } + if (!elemref) { + elemref = sp_lpe_item->parent->appendChildRepr(rtext); + Inkscape::GC::release(rtext); + } else if (elemref->parent != sp_lpe_item->parent) { + Inkscape::XML::Node *old_repr = elemref->getRepr(); + Inkscape::XML::Node *copy = old_repr->duplicate(xml_doc); + SPObject * elemref_copy = sp_lpe_item->parent->appendChildRepr(copy); + Inkscape::GC::release(copy); + elemref->deleteObject(); + copy->setAttribute("id", id); + elemref = elemref_copy; + } + elements.push_back(id); + Geom::OptRect bounds = SP_ITEM(elemref)->bounds(SPItem::GEOMETRIC_BBOX); + if (bounds) { + anotation_width = bounds->width() * 1.4; } } void LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, const char * id, bool main, bool overflow, bool remove, bool arrows) { - if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { - Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); - Inkscape::URI SVGElem_uri(Glib::ustring("#").append(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::PathVector line_pathv; - if (main && std::abs(text_top_bottom) < fontsize/1.5 && hide_back && !overflow){ - 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<Geom::LineSegment>(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<Geom::LineSegment>(end); - line_pathv.push_back(line_path); + SPDocument * document = SP_ACTIVE_DOCUMENT; + Inkscape::XML::Document *xml_doc = document->getReprDoc(); + 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::PathVector line_pathv; + if (main && std::abs(text_top_bottom) < fontsize/1.5 && hide_back && !overflow){ + Geom::Path line_path; + double k = 0; + if (flip_side) { + k = (Geom::distance(start,end)/2.0) + arrow_gap - (anotation_width/2.0); } else { - Geom::Path line_path; - line_path.start(start); - line_path.appendNew<Geom::LineSegment>(end); - line_pathv.push_back(line_path); + k = (Geom::distance(start,end)/2.0) - arrow_gap - (anotation_width/2.0); } - if (elemref = SVGElemRef->getObject()) { - if (remove) { - elemref->deleteObject(); - return; - } - line = elemref->getRepr(); - - const char * line_str = sp_svg_write_path( line_pathv ); - line->setAttribute("d" , line_str); - line->setAttribute("transform", NULL); - } else { - if (remove) { - return; - } - line = xml_doc->createElement("svg:path"); - line->setAttribute("id", id); - const char * line_str = sp_svg_write_path( line_pathv ); - line->setAttribute("d" , line_str); + if (Geom::distance(start,end) < anotation_width){ + return; } - line->setAttribute("sodipodi:insensitive", "true"); - line_pathv.clear(); - - Glib::ustring style = Glib::ustring("stroke:#000000;fill:none;"); - 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);"); - } else { - style = style + Glib::ustring("marker-start:url(#ArrowDIN-start);marker-end:url(#ArrowDIN-end);"); - } - } else { - line->setAttribute("inkscape:label", "dinhelpline"); + Geom::Ray ray(end, start); + Geom::Coord angle = ray.angle(); + line_path.start(start); + line_path.appendNew<Geom::LineSegment>(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<Geom::LineSegment>(end); + line_pathv.push_back(line_path); + } else { + Geom::Path line_path; + line_path.start(start); + line_path.appendNew<Geom::LineSegment>(end); + line_pathv.push_back(line_path); + } + if (elemref = document->getObjectById(id)) { + if (remove) { + elemref->deleteObject(); + return; } - std::stringstream stroke_w; - stroke_w.imbue(std::locale::classic()); - if (line_group_05) { - 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:" + stroke_w.str()); - } else { - 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:" + stroke_w.str()); + line = elemref->getRepr(); + + const char * line_str = sp_svg_write_path( line_pathv ); + line->setAttribute("d" , line_str); + line->setAttribute("transform", NULL); + } else { + if (remove) { + return; } - 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()); + line = xml_doc->createElement("svg:path"); + line->setAttribute("id", id); + const char * line_str = sp_svg_write_path( line_pathv ); + line->setAttribute("d" , line_str); + } + line->setAttribute("sodipodi:insensitive", "true"); + line_pathv.clear(); + + Glib::ustring style = Glib::ustring("stroke:#000000;fill:none;"); + 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);"); } 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()); - if (!elemref) { - elemref = sp_lpe_item->parent->appendChildRepr(line); - Inkscape::GC::release(line); - } else if (elemref->parent != sp_lpe_item->parent) { - Inkscape::XML::Node *old_repr = elemref->getRepr(); - Inkscape::XML::Node *copy = old_repr->duplicate(xml_doc); - SPObject * elemref_copy = sp_lpe_item->parent->appendChildRepr(copy); - Inkscape::GC::release(copy); - elemref->deleteObject(); - copy->setAttribute("id", id); + style = style + Glib::ustring("marker-start:url(#ArrowDIN-start);marker-end:url(#ArrowDIN-end);"); } - elements.push_back(id); + } 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 / doc_scale, "mm", display_unit.c_str()); + stroke_w << stroke_width; + style = style + Glib::ustring("stroke-width:" + stroke_w.str()); + } else { + 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:" + stroke_w.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()); + if (!elemref) { + elemref = sp_lpe_item->parent->appendChildRepr(line); + Inkscape::GC::release(line); + } else if (elemref->parent != sp_lpe_item->parent) { + Inkscape::XML::Node *old_repr = elemref->getRepr(); + Inkscape::XML::Node *copy = old_repr->duplicate(xml_doc); + SPObject * elemref_copy = sp_lpe_item->parent->appendChildRepr(copy); + Inkscape::GC::release(copy); + elemref->deleteObject(); + copy->setAttribute("id", id); + } + elements.push_back(id); } void @@ -514,171 +499,168 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) { SPLPEItem * splpeitem = const_cast<SPLPEItem *>(lpeitem); sp_lpe_item->parent = dynamic_cast<SPObject *>(splpeitem->parent); - SPDocument * doc = SP_ACTIVE_DOCUMENT; + SPDocument * document = SP_ACTIVE_DOCUMENT; Inkscape::XML::Node *root = splpeitem->document->getReprRoot(); - Inkscape::XML::Node *root_origin = doc->getReprRoot(); + Inkscape::XML::Node *root_origin = document->getReprRoot(); if (root_origin != root) { return; } SPPath *sp_path = dynamic_cast<SPPath *>(splpeitem); if (sp_path) { - Geom::Affine affinetransform = i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(doc->getRoot())); + Geom::Affine affinetransform = i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(document->getRoot())); Geom::PathVector pathvector = sp_path->get_original_curve()->get_pathvector(); Geom::Affine writed_transform = Geom::identity(); sp_svg_transform_read(splpeitem->getAttribute("transform"), &writed_transform ); pathvector *= writed_transform; - if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { - if ((Glib::ustring(format.param_getSVGValue()).empty())) { - format.param_setValue(Glib::ustring("{measure}{unit}")); - format.write_to_SVG(); - } - size_t ncurves = pathvector.curveCount(); - if (ncurves != (size_t)curve_linked.param_get_max()) { - curve_linked.param_set_range(0, ncurves); - } - 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); + if ((Glib::ustring(format.param_getSVGValue()).empty())) { + format.param_setValue(Glib::ustring("{measure}{unit}")); + this->upd_params = true; + } + size_t ncurves = pathvector.curveCount(); + if (ncurves != (size_t)curve_linked.param_get_max()) { + curve_linked.param_set_range(0, ncurves); + } + 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); + } + if (Geom::are_near(start, start_stored, 0.01) && + Geom::are_near(end, end_stored, 0.01) && + sp_lpe_item->getCurrentLPE() != this){ + return; + } + elements.clear(); + start_stored = start; + end_stored = end; + Geom::Point hstart = start; + Geom::Point hend = end; + bool remove = false; + if (Geom::are_near(hstart, hend)) { + remove = true; + } + if (orientation == OM_VERTICAL) { + Coord xpos = std::max(hstart[Geom::X],hend[Geom::X]); + if (flip_side) { + xpos = std::min(hstart[Geom::X],hend[Geom::X]); } - if (Geom::are_near(start, start_stored, 0.01) && - Geom::are_near(end, end_stored, 0.01) && - sp_lpe_item->getCurrentLPE() != this){ - return; + hstart[Geom::X] = xpos; + hend[Geom::X] = xpos; + if (hstart[Geom::Y] > hend[Geom::Y]) { + swap(hstart,hend); + swap(start,end); } - elements.clear(); - start_stored = start; - end_stored = end; - Geom::Point hstart = start; - Geom::Point hend = end; - bool remove = false; - if (Geom::are_near(hstart, hend)) { + if (Geom::are_near(hstart[Geom::Y], hend[Geom::Y])) { remove = true; } - if (orientation == OM_VERTICAL) { - Coord xpos = std::max(hstart[Geom::X],hend[Geom::X]); - if (flip_side) { - xpos = std::min(hstart[Geom::X],hend[Geom::X]); - } - 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) { - Coord ypos = std::max(hstart[Geom::Y],hend[Geom::Y]); - if (flip_side) { - ypos = std::min(hstart[Geom::Y],hend[Geom::Y]); - } - 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; - } - } - 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(); + } + if (orientation == OM_HORIZONTAL) { + Coord ypos = std::max(hstart[Geom::Y],hend[Geom::Y]); if (flip_side) { - angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); - if (angle < 0) angle += 2*M_PI; - } - if (arrows_outside) { - createArrowMarker("ArrowDINout-start"); - createArrowMarker("ArrowDINout-end"); - } else { - createArrowMarker("ArrowDIN-start"); - createArrowMarker("ArrowDIN-end"); + ypos = std::min(hstart[Geom::Y],hend[Geom::Y]); } - //We get the font size to offset the text to the middle - Pango::FontDescription fontdesc(Glib::ustring(fontbutton.param_getSVGValue())); - 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_top_bottom) + fontsize/2.5); - } else { - pos = pos - Point::polar(angle_cross, (position + text_top_bottom) - fontsize/2.5); + hstart[Geom::Y] = ypos; + hend[Geom::Y] = ypos; + if (hstart[Geom::X] < hend[Geom::X]) { + swap(hstart,hend); + swap(start,end); } - double parents_scale = (affinetransform.expansionX() + affinetransform.expansionY()) / 2.0; - if (scale_sensitive) { - length *= parents_scale; + if (Geom::are_near(hstart[Geom::X], hend[Geom::X])) { + remove = true; } - if (scale_sensitive && !affinetransform.preservesAngles()) { - createTextLabel(pos, length, angle, remove, false); - } else { - createTextLabel(pos, length, angle, remove, true); + } + 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(); + if (flip_side) { + angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); + if (angle < 0) angle += 2*M_PI; + } + if (arrows_outside) { + createArrowMarker("ArrowDINout-start"); + createArrowMarker("ArrowDINout-end"); + } else { + createArrowMarker("ArrowDIN-start"); + createArrowMarker("ArrowDIN-end"); + } + //We get the font size to offset the text to the middle + Pango::FontDescription fontdesc(Glib::ustring(fontbutton.param_getSVGValue())); + fontsize = fontdesc.get_size()/(double)Pango::SCALE; + fontsize *= document->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_top_bottom) + fontsize/2.5); + } else { + pos = pos - Point::polar(angle_cross, (position + text_top_bottom) - fontsize/2.5); + } + double parents_scale = (affinetransform.expansionX() + affinetransform.expansionY()) / 2.0; + if (scale_sensitive) { + length *= parents_scale; + } + if (scale_sensitive && !affinetransform.preservesAngles()) { + createTextLabel(pos, length, angle, remove, false); + } else { + createTextLabel(pos, length, angle, remove, true); + } + bool overflow = false; + const char * downline = g_strdup(Glib::ustring("downline-").append(this->getRepr()->attribute("id")).c_str()); + 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); } - bool overflow = false; - const char * downline = g_strdup(Glib::ustring("downline-").append(this->getRepr()->attribute("id")).c_str()); - 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)); - } + 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 { - 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)); - } + prog_end = sstart + Point::polar(angle, std::abs(text_right_left) - (anotation_width/1.9) - (Geom::distance(start,end)/2.0)); } - overflow = true; - createLine(sstart, prog_end, downline, true, overflow, false, false); } else { - //erase it - createLine(Geom::Point(),Geom::Point(), downline, 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) { - 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()); - setlocale(LC_NUMERIC, std::locale::classic().name().c_str()); - double width_line = atof(sp_repr_css_property(css,"stroke-width","-1")); - 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; - } - hstart = hstart - Point::polar(angle_cross, position); - createLine(start, hstart, g_strdup(Glib::ustring("infoline-on-start-").append(this->getRepr()->attribute("id")).c_str()), false, false, remove); - hend = hend - Point::polar(angle_cross, position); - createLine(end, hend, g_strdup(Glib::ustring("infoline-on-end-").append(this->getRepr()->attribute("id")).c_str()), false, false, remove); - if (!arrows_outside) { - hstart = hstart + Point::polar(angle, arrow_gap); - hend = hend - Point::polar(angle, arrow_gap ); + 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)); + } } - createLine(hstart, hend, g_strdup(Glib::ustring("infoline-").append(this->getRepr()->attribute("id")).c_str()), true, overflow, remove, true); - + overflow = true; + createLine(sstart, prog_end, downline, true, overflow, false, false); + } else { + //erase it + createLine(Geom::Point(),Geom::Point(), downline, 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) { + 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()); + setlocale(LC_NUMERIC, std::locale::classic().name().c_str()); + double width_line = atof(sp_repr_css_property(css,"stroke-width","-1")); + 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; + } + hstart = hstart - Point::polar(angle_cross, position); + createLine(start, hstart, g_strdup(Glib::ustring("infoline-on-start-").append(this->getRepr()->attribute("id")).c_str()), false, false, remove); + hend = hend - Point::polar(angle_cross, position); + createLine(end, hend, g_strdup(Glib::ustring("infoline-on-end-").append(this->getRepr()->attribute("id")).c_str()), false, false, remove); + if (!arrows_outside) { + hstart = hstart + Point::polar(angle, arrow_gap); + hend = hend - Point::polar(angle, arrow_gap ); + } + createLine(hstart, hend, g_strdup(Glib::ustring("infoline-").append(this->getRepr()->attribute("id")).c_str()), true, overflow, remove, true); } } @@ -704,59 +686,48 @@ LPEMeasureLine::doOnRemove (SPLPEItem const* /*lpeitem*/) void LPEMeasureLine::processObjects(LpeAction lpe_action) { - if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { - for (std::vector<const char *>::iterator el_it = elements.begin(); - el_it != elements.end(); ++el_it) { - const char * id = *el_it; - if (!id || strlen(id) == 0) { - return; - } - Inkscape::URI SVGElem_uri(Glib::ustring("#").append(id).c_str()); - Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); - SVGElemRef->attach(SVGElem_uri); - SPObject *elemref = NULL; - if (elemref = SVGElemRef->getObject()) { - Inkscape::XML::Node * elemnode = elemref->getRepr(); - std::vector<SPItem*> item_list; - item_list.push_back(SP_ITEM(elemref)); - std::vector<Inkscape::XML::Node*> item_to_select; - std::vector<SPItem*> item_selected; - SPCSSAttr *css; - Glib::ustring css_str; - switch (lpe_action){ - case LPE_TO_OBJECTS: - if (elemnode->attribute("inkscape:path-effect")) { - sp_item_list_to_curves(item_list, item_selected, item_to_select); - } - elemnode->setAttribute("sodipodi:insensitive", NULL); - break; - - case LPE_ERASE: - if (std::strcmp(elemref->getId(),id_origin.param_getSVGValue()) != 0) { - elemref->deleteObject(); - } - break; + SPDocument * document = SP_ACTIVE_DOCUMENT; + for (std::vector<const char *>::iterator el_it = elements.begin(); + el_it != elements.end(); ++el_it) { + const char * id = *el_it; + if (!id || strlen(id) == 0) { + return; + } + SPObject *elemref = NULL; + if (elemref = document->getObjectById(id)) { + SPCSSAttr *css; + Glib::ustring css_str; + switch (lpe_action){ + case LPE_TO_OBJECTS: + elemref->getRepr()->setAttribute("inkscape:path-effect", NULL); + elemref->getRepr()->setAttribute("sodipodi:insensitive", NULL); + break; - case LPE_VISIBILITY: - css = sp_repr_css_attr_new(); - sp_repr_css_attr_add_from_string(css, elemref->getRepr()->attribute("style")); - if (!this->isVisible() && std::strcmp(elemref->getId(),id_origin.param_getSVGValue()) != 0) { - css->setAttribute("display", "none"); - } else { - css->setAttribute("display", NULL); - } - sp_repr_css_write_string(css,css_str); - elemnode->setAttribute("style", css_str.c_str()); - break; + case LPE_ERASE: + if (std::strcmp(elemref->getId(),id_origin.param_getSVGValue()) != 0) { + elemref->deleteObject(); + } + break; - default: - break; + case LPE_VISIBILITY: + css = sp_repr_css_attr_new(); + sp_repr_css_attr_add_from_string(css, elemref->getRepr()->attribute("style")); + if (!this->isVisible() && std::strcmp(elemref->getId(),id_origin.param_getSVGValue()) != 0) { + css->setAttribute("display", "none"); + } else { + css->setAttribute("display", NULL); } + sp_repr_css_write_string(css,css_str); + elemref->getRepr()->setAttribute("style", css_str.c_str()); + break; + + default: + break; } } - if (lpe_action == LPE_ERASE || lpe_action == LPE_TO_OBJECTS) { - elements.clear(); - } + } + if (lpe_action == LPE_ERASE) { + elements.clear(); } } diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 2cc187fb4..65177579d 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -140,8 +140,10 @@ LPEMirrorSymmetry::doAfterEffect (SPLPEItem const* lpeitem) void LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) { + SPObject * current_layer = NULL; if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { Inkscape::Selection *sel = desktop->getSelection(); + current_layer = sel->layers()->currentLayer(); if ( sel && !sel->isEmpty()) { SPItem *item = sel->singleItem(); if (item) { @@ -151,6 +153,7 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) } } } + SPDocument * document = SP_ACTIVE_DOCUMENT; using namespace Geom; original_bbox(lpeitem); Point point_a(boundingbox_X.max(), boundingbox_Y.min()); @@ -177,25 +180,23 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) end_point.param_setValue(end_point * trans, true); } } else if ( mode == MT_V){ - if(SP_ACTIVE_DESKTOP){ - SPDocument * doc = SP_ACTIVE_DESKTOP->getDocument(); - Geom::Rect view_box_rect = doc->getViewBox(); + if(current_layer){ + Geom::Rect view_box_rect = document->getViewBox(); Geom::Point sp = Geom::Point(view_box_rect.width()/2.0, 0); - sp *= i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(SP_ACTIVE_DESKTOP->currentLayer()->parent)) .inverse(); + sp *= i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(current_layer->parent)) .inverse(); start_point.param_setValue(sp); Geom::Point ep = Geom::Point(view_box_rect.width()/2.0, view_box_rect.height()); - ep *= i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(SP_ACTIVE_DESKTOP->currentLayer()->parent)) .inverse(); + ep *= i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(current_layer->parent)).inverse(); end_point.param_setValue(ep, true); } } else { //horizontal page - if(SP_ACTIVE_DESKTOP){ - SPDocument * doc = SP_ACTIVE_DESKTOP->getDocument(); - Geom::Rect view_box_rect = doc->getViewBox(); + if(current_layer){ + Geom::Rect view_box_rect = document->getViewBox(); Geom::Point sp = Geom::Point(0, view_box_rect.height()/2.0); - sp *= i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(SP_ACTIVE_DESKTOP->currentLayer()->parent)) .inverse(); + sp *= i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(current_layer->parent)).inverse(); start_point.param_setValue(sp); Geom::Point ep = Geom::Point(view_box_rect.width(), view_box_rect.height()/2.0); - ep *= i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(SP_ACTIVE_DESKTOP->currentLayer()->parent)) .inverse(); + ep *= i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(current_layer->parent)).inverse(); end_point.param_setValue(ep, true); } } @@ -271,53 +272,48 @@ LPEMirrorSymmetry::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, c void LPEMirrorSymmetry::createMirror(Geom::Affine transform) { - if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { - const char * id_origin_char = id_origin.param_getSVGValue(); - const char * mirror = g_strdup(Glib::ustring("mirror-").append(id_origin_char).c_str()); - const char * elemref_id; - if (std::strcmp(sp_lpe_item->getId(), mirror) == 0) { - elemref_id = id_origin_char; - } else { - elemref_id = mirror; - } - elements.clear(); - elements.push_back(id_origin_char); - elements.push_back(mirror); - Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); - Inkscape::URI SVGElem_uri(Glib::ustring("#").append(elemref_id).c_str()); - Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); - SVGElemRef->attach(SVGElem_uri); - SPObject *elemref= NULL; - Inkscape::XML::Node *phantom = NULL; - if (elemref = SVGElemRef->getObject()) { - phantom = elemref->getRepr(); - } else { - phantom = sp_lpe_item->getRepr()->duplicate(xml_doc); - } - phantom->setAttribute("id", elemref_id); - if (!elemref) { - elemref = container->appendChildRepr(phantom); - Inkscape::GC::release(phantom); - } - cloneAttrbutes(SP_OBJECT(sp_lpe_item), elemref, true, "inkscape:original-d", "d", "inkscape:path-effect", NULL); //NULL required - //transform *= last_transform; - //if (transform != Geom::identity()) { - if (elemref_id == mirror) { - elemref->getRepr()->setAttribute("transform" , sp_svg_transform_write(transform)); - } else { - sp_lpe_item->getRepr()->setAttribute("transform" , sp_svg_transform_write(transform)); - } - //} - if (elemref->parent != container) { - Inkscape::XML::Node *copy = phantom->duplicate(xml_doc); - copy->setAttribute("id", elemref_id); - other = container->appendChildRepr(copy); - Inkscape::GC::release(copy); - elemref->deleteObject(); + SPDocument * document = SP_ACTIVE_DOCUMENT; + const char * id_origin_char = id_origin.param_getSVGValue(); + const char * mirror = g_strdup(Glib::ustring("mirror-").append(id_origin_char).c_str()); + const char * elemref_id; + if (std::strcmp(sp_lpe_item->getId(), mirror) == 0) { + elemref_id = id_origin_char; + } else { + elemref_id = mirror; + } + elements.clear(); + elements.push_back(id_origin_char); + elements.push_back(mirror); + Inkscape::XML::Document *xml_doc = document->getReprDoc(); + SPObject *elemref= NULL; + Inkscape::XML::Node *phantom = NULL; + if (elemref = document->getObjectById(elemref_id)) { + phantom = elemref->getRepr(); + } else { + phantom = sp_lpe_item->getRepr()->duplicate(xml_doc); + } + phantom->setAttribute("id", elemref_id); + if (!elemref) { + elemref = container->appendChildRepr(phantom); + Inkscape::GC::release(phantom); + } + cloneAttrbutes(SP_OBJECT(sp_lpe_item), elemref, true, "inkscape:original-d", "d", "inkscape:path-effect", NULL); //NULL required + //transform *= last_transform; + //if (transform != Geom::identity()) { + if (elemref_id == mirror) { + elemref->getRepr()->setAttribute("transform" , sp_svg_transform_write(transform)); } else { - other = elemref; + sp_lpe_item->getRepr()->setAttribute("transform" , sp_svg_transform_write(transform)); } - + //} + if (elemref->parent != container) { + Inkscape::XML::Node *copy = phantom->duplicate(xml_doc); + copy->setAttribute("id", elemref_id); + other = container->appendChildRepr(copy); + Inkscape::GC::release(copy); + elemref->deleteObject(); + } else { + other = elemref; } } @@ -379,59 +375,54 @@ LPEMirrorSymmetry::doOnRemove (SPLPEItem const* /*lpeitem*/) void LPEMirrorSymmetry::processObjects(LpeAction lpe_action) { - if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { - for (std::vector<const char *>::iterator el_it = elements.begin(); - el_it != elements.end(); ++el_it) { - const char * id = *el_it; - if (!id || strlen(id) == 0) { - return; - } - Inkscape::URI SVGElem_uri(Glib::ustring("#").append(id).c_str()); - Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); - SVGElemRef->attach(SVGElem_uri); - SPObject *elemref = NULL; - if (elemref = SVGElemRef->getObject()) { - Inkscape::XML::Node * elemnode = elemref->getRepr(); - std::vector<SPItem*> item_list; - item_list.push_back(SP_ITEM(elemref)); - std::vector<Inkscape::XML::Node*> item_to_select; - std::vector<SPItem*> item_selected; - SPCSSAttr *css; - Glib::ustring css_str; - switch (lpe_action){ - case LPE_TO_OBJECTS: - if (elemnode->attribute("inkscape:path-effect")) { - sp_item_list_to_curves(item_list, item_selected, item_to_select); - } - elemnode->setAttribute("sodipodi:insensitive", NULL); - break; - - case LPE_ERASE: - //if (std::strcmp(elemref->getId(),sp_lpe_item->getId()) != 0) { - elemref->deleteObject(); - //} - break; - - case LPE_VISIBILITY: - css = sp_repr_css_attr_new(); - sp_repr_css_attr_add_from_string(css, elemref->getRepr()->attribute("style")); - if (!this->isVisible()/* && std::strcmp(elemref->getId(),sp_lpe_item->getId()) != 0*/) { - css->setAttribute("display", "none"); - } else { - css->setAttribute("display", NULL); - } - sp_repr_css_write_string(css,css_str); - elemnode->setAttribute("style", css_str.c_str()); - break; - - default: - break; + for (std::vector<const char *>::iterator el_it = elements.begin(); + el_it != elements.end(); ++el_it) { + const char * id = *el_it; + if (!id || strlen(id) == 0) { + return; + } + SPObject *elemref = NULL; + if (elemref = document->getObjectById(id)) { + Inkscape::XML::Node * elemnode = elemref->getRepr(); + std::vector<SPItem*> item_list; + item_list.push_back(SP_ITEM(elemref)); + std::vector<Inkscape::XML::Node*> item_to_select; + std::vector<SPItem*> item_selected; + SPCSSAttr *css; + Glib::ustring css_str; + switch (lpe_action){ + case LPE_TO_OBJECTS: + if (elemnode->attribute("inkscape:path-effect")) { + sp_item_list_to_curves(item_list, item_selected, item_to_select); + } + elemnode->setAttribute("sodipodi:insensitive", NULL); + break; + + case LPE_ERASE: + //if (std::strcmp(elemref->getId(),sp_lpe_item->getId()) != 0) { + elemref->deleteObject(); + //} + break; + + case LPE_VISIBILITY: + css = sp_repr_css_attr_new(); + sp_repr_css_attr_add_from_string(css, elemref->getRepr()->attribute("style")); + if (!this->isVisible()/* && std::strcmp(elemref->getId(),sp_lpe_item->getId()) != 0*/) { + css->setAttribute("display", "none"); + } else { + css->setAttribute("display", NULL); } + sp_repr_css_write_string(css,css_str); + elemnode->setAttribute("style", css_str.c_str()); + break; + + default: + break; } } - if (lpe_action == LPE_ERASE || lpe_action == LPE_TO_OBJECTS) { - elements.clear(); - } + } + if (lpe_action == LPE_ERASE || lpe_action == LPE_TO_OBJECTS) { + elements.clear(); } } diff --git a/src/live_effects/lpe-patternalongpath.cpp b/src/live_effects/lpe-patternalongpath.cpp index 9cfeffee7..e5c9f1be1 100644 --- a/src/live_effects/lpe-patternalongpath.cpp +++ b/src/live_effects/lpe-patternalongpath.cpp @@ -275,10 +275,10 @@ LPEPatternAlongPath::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vect void -LPEPatternAlongPath::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) +LPEPatternAlongPath::addKnotHolderEntities(KnotHolder *knotholder, SPItem *item) { KnotHolderEntity *e = new WPAP::KnotHolderEntityWidthPatternAlongPath(this); - e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _("Change the width"), SP_KNOT_SHAPE_CIRCLE); + e->create(NULL, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _("Change the width"), SP_KNOT_SHAPE_CIRCLE); knotholder->add(e); } diff --git a/src/live_effects/lpe-patternalongpath.h b/src/live_effects/lpe-patternalongpath.h index 3d7fc02bc..c34a9a15d 100644 --- a/src/live_effects/lpe-patternalongpath.h +++ b/src/live_effects/lpe-patternalongpath.h @@ -43,7 +43,7 @@ public: void addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector<Geom::PathVector> &hp_vec); - virtual void addKnotHolderEntities(KnotHolder * knotholder, SPDesktop * desktop, SPItem * item); + virtual void addKnotHolderEntities(KnotHolder * knotholder, SPItem * item); PathParam pattern; diff --git a/src/live_effects/lpe-perspective_path.cpp b/src/live_effects/lpe-perspective_path.cpp index 2c6d66cee..979b6dea5 100644 --- a/src/live_effects/lpe-perspective_path.cpp +++ b/src/live_effects/lpe-perspective_path.cpp @@ -18,7 +18,6 @@ #include "live_effects/lpeobject.h" #include "knot-holder-entity.h" #include "knotholder.h" -#include "desktop.h" #include <util/units.h> // TODO due to internal breakage in glibmm headers, this must be last: @@ -243,9 +242,9 @@ LPEPerspectivePath::newWidget() return dynamic_cast<Gtk::Widget *>(vbox); } -void LPEPerspectivePath::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) { +void LPEPerspectivePath::addKnotHolderEntities(KnotHolder *knotholder, SPItem *item) { KnotHolderEntity *e = new PP::KnotHolderEntityOffset(this); - e->create( desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, + e->create( NULL, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _("Adjust the origin") ); knotholder->add(e); }; diff --git a/src/live_effects/lpe-perspective_path.h b/src/live_effects/lpe-perspective_path.h index c4ddf1853..87ee453ff 100644 --- a/src/live_effects/lpe-perspective_path.h +++ b/src/live_effects/lpe-perspective_path.h @@ -41,7 +41,7 @@ public: virtual Gtk::Widget * newWidget(); /* the knotholder entity classes must be declared friends */ friend class PP::KnotHolderEntityOffset; - void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); + void addKnotHolderEntities(KnotHolder *knotholder, SPItem *item); private: // add the parameters for your effect here: diff --git a/src/live_effects/lpe-simplify.cpp b/src/live_effects/lpe-simplify.cpp index 8bdb19b4f..5de9816bb 100644 --- a/src/live_effects/lpe-simplify.cpp +++ b/src/live_effects/lpe-simplify.cpp @@ -140,11 +140,7 @@ LPESimplify::doEffect(SPCurve *curve) Geom::PathVector result = Geom::parse_svg_path(pathliv->svg_dump_path()); generateHelperPathAndSmooth(result); curve->set_pathvector(result); - SPDesktop* desktop = SP_ACTIVE_DESKTOP; - if(desktop && INK_IS_NODE_TOOL(desktop->event_context)) { - Inkscape::UI::Tools::NodeTool *nt = static_cast<Inkscape::UI::Tools::NodeTool*>(desktop->event_context); - nt->update_helperpath(); - } + Inkscape::UI::Tools::sp_update_helperpath(); } void diff --git a/src/live_effects/lpe-skeleton.cpp b/src/live_effects/lpe-skeleton.cpp index adc4a3493..4fc18cee2 100644 --- a/src/live_effects/lpe-skeleton.cpp +++ b/src/live_effects/lpe-skeleton.cpp @@ -97,10 +97,10 @@ public: } // namespace Skeleton void -LPESkeleton::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) { +LPESkeleton::addKnotHolderEntities(KnotHolder *knotholder, SPItem *item) { { KnotHolderEntityMyHandle *e = new KnotHolderEntityMyHandle(this); - e->create( desktop, item, knotholder, + e->create( NULL, item, knotholder, _("Text describing what this handle does"), //optional: knot_shape, knot_mode, knot_color); knotholder->add(e); diff --git a/src/live_effects/lpe-skeleton.h b/src/live_effects/lpe-skeleton.h index 3b45b6978..e633ba5ab 100644 --- a/src/live_effects/lpe-skeleton.h +++ b/src/live_effects/lpe-skeleton.h @@ -41,7 +41,7 @@ public: /* the knotholder entity classes (if any) can be declared friends */ //friend class Skeleton::KnotHolderEntityMyHandle; - //virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); + //virtual void addKnotHolderEntities(KnotHolder *knotholder, SPItem *item); private: // add the parameters for your effect here: diff --git a/src/live_effects/lpe-spiro.cpp b/src/live_effects/lpe-spiro.cpp index 4a41dc5a0..8ea57bee4 100644 --- a/src/live_effects/lpe-spiro.cpp +++ b/src/live_effects/lpe-spiro.cpp @@ -16,8 +16,6 @@ // For handling un-continuous paths: #include "message-stack.h" #include "inkscape.h" -#include "desktop.h" - namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-tangent_to_curve.cpp b/src/live_effects/lpe-tangent_to_curve.cpp index 76d4ea71b..5f63e1ee9 100644 --- a/src/live_effects/lpe-tangent_to_curve.cpp +++ b/src/live_effects/lpe-tangent_to_curve.cpp @@ -92,22 +92,22 @@ LPETangentToCurve::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const } void -LPETangentToCurve::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) { +LPETangentToCurve::addKnotHolderEntities(KnotHolder *knotholder, SPItem *item) { { KnotHolderEntity *e = new TtC::KnotHolderEntityAttachPt(this); - e->create( desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, + e->create( NULL, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _("Adjust the point of attachment of the tangent") ); knotholder->add(e); } { KnotHolderEntity *e = new TtC::KnotHolderEntityLeftEnd(this); - e->create( desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, + e->create( NULL, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _("Adjust the <b>left</b> end of the tangent") ); knotholder->add(e); } { KnotHolderEntity *e = new TtC::KnotHolderEntityRightEnd(this); - e->create( desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, + e->create( NULL, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _("Adjust the <b>right</b> end of the tangent") ); knotholder->add(e); } diff --git a/src/live_effects/lpe-tangent_to_curve.h b/src/live_effects/lpe-tangent_to_curve.h index 8e44c01d1..a6a3c17ca 100644 --- a/src/live_effects/lpe-tangent_to_curve.h +++ b/src/live_effects/lpe-tangent_to_curve.h @@ -41,7 +41,7 @@ public: friend class TtC::KnotHolderEntityLeftEnd; friend class TtC::KnotHolderEntityRightEnd; friend class TtC::KnotHolderEntityAttachPt; - virtual void addKnotHolderEntities(KnotHolder * knotholder, SPDesktop * desktop, SPItem * item); + virtual void addKnotHolderEntities(KnotHolder * knotholder, SPItem * item); private: ScalarParam angle; diff --git a/src/live_effects/lpe-taperstroke.cpp b/src/live_effects/lpe-taperstroke.cpp index 4ffc41691..f4a81aa90 100644 --- a/src/live_effects/lpe-taperstroke.cpp +++ b/src/live_effects/lpe-taperstroke.cpp @@ -435,14 +435,14 @@ Piecewise<D2<SBasis> > stretch_along(Piecewise<D2<SBasis> > pwd2_in, Geom::Path } } -void LPETaperStroke::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) +void LPETaperStroke::addKnotHolderEntities(KnotHolder *knotholder, SPItem *item) { KnotHolderEntity *e = new TpS::KnotHolderEntityAttachBegin(this); - e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _("Start point of the taper"), SP_KNOT_SHAPE_CIRCLE); + e->create(NULL, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _("Start point of the taper"), SP_KNOT_SHAPE_CIRCLE); knotholder->add(e); KnotHolderEntity *f = new TpS::KnotHolderEntityAttachEnd(this); - f->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _("End point of the taper"), SP_KNOT_SHAPE_CIRCLE); + f->create(NULL, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _("End point of the taper"), SP_KNOT_SHAPE_CIRCLE); knotholder->add(f); } diff --git a/src/live_effects/lpe-taperstroke.h b/src/live_effects/lpe-taperstroke.h index 88604486e..e3ecbb56c 100644 --- a/src/live_effects/lpe-taperstroke.h +++ b/src/live_effects/lpe-taperstroke.h @@ -36,7 +36,7 @@ public: virtual Geom::PathVector doEffect_path (Geom::PathVector const& path_in); Geom::PathVector doEffect_simplePath(Geom::PathVector const& path_in); - virtual void addKnotHolderEntities(KnotHolder * knotholder, SPDesktop * desktop, SPItem * item); + virtual void addKnotHolderEntities(KnotHolder * knotholder, SPItem * item); friend class TpS::KnotHolderEntityAttachBegin; friend class TpS::KnotHolderEntityAttachEnd; diff --git a/src/live_effects/parameter/filletchamferpointarray.cpp b/src/live_effects/parameter/filletchamferpointarray.cpp index b321a5831..7696288b0 100644 --- a/src/live_effects/parameter/filletchamferpointarray.cpp +++ b/src/live_effects/parameter/filletchamferpointarray.cpp @@ -24,7 +24,6 @@ #include "selection.h" // needed for on-canvas editting: -#include "desktop.h" #include "live_effects/lpeobject.h" #include "helper/geom-nodetype.h" #include "helper/geom-curves.h" @@ -825,10 +824,7 @@ void FilletChamferPointArrayParamKnotHolderEntity::knot_set_offset( this->parent_holder->knot_ungrabbed_handler(this->knot, 0); } -void FilletChamferPointArrayParam::addKnotHolderEntities(KnotHolder *knotholder, - SPDesktop *desktop, - SPItem *item) -{ +void FilletChamferPointArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPItem *item) { recalculate_knots(get_pwd2()); for (unsigned int i = 0; i < _vector.size(); ++i) { if (_vector[i][Y] <= 0) { @@ -854,7 +850,7 @@ void FilletChamferPointArrayParam::addKnotHolderEntities(KnotHolder *knotholder, } FilletChamferPointArrayParamKnotHolderEntity *e = new FilletChamferPointArrayParamKnotHolderEntity(this, i); - e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _(tip), + e->create(NULL, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _(tip), knot_shape, knot_mode, knot_color); knotholder->add(e); } diff --git a/src/live_effects/parameter/filletchamferpointarray.h b/src/live_effects/parameter/filletchamferpointarray.h index 48cd26d2d..b81339a69 100644 --- a/src/live_effects/parameter/filletchamferpointarray.h +++ b/src/live_effects/parameter/filletchamferpointarray.h @@ -59,8 +59,7 @@ public: return true; } virtual void updateCanvasIndicators(); - virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, - SPItem *item); + virtual void addKnotHolderEntities(KnotHolder *knotholder, SPItem *item); void set_pwd2(Geom::Piecewise<Geom::D2<Geom::SBasis> > const &pwd2_in, Geom::Piecewise<Geom::D2<Geom::SBasis> > const &pwd2_normal_in); diff --git a/src/live_effects/parameter/parameter.h b/src/live_effects/parameter/parameter.h index 5dbcb7868..6cf10710c 100644 --- a/src/live_effects/parameter/parameter.h +++ b/src/live_effects/parameter/parameter.h @@ -68,7 +68,7 @@ public: // overload these for your particular parameter to make it provide knotholder handles or canvas helperpaths virtual bool providesKnotHolderEntities() const { return false; } - virtual void addKnotHolderEntities(KnotHolder */*knotholder*/, SPDesktop */*desktop*/, SPItem */*item*/) {}; + virtual void addKnotHolderEntities(KnotHolder */*knotholder*/, SPItem */*item*/) {}; virtual void addCanvasIndicators(SPLPEItem const*/*lpeitem*/, std::vector<Geom::PathVector> &/*hp_vec*/) {}; virtual void param_editOncanvas(SPItem * /*item*/, SPDesktop * /*dt*/) {}; diff --git a/src/live_effects/parameter/point.cpp b/src/live_effects/parameter/point.cpp index 3442fd851..c87b1e299 100644 --- a/src/live_effects/parameter/point.cpp +++ b/src/live_effects/parameter/point.cpp @@ -15,9 +15,6 @@ #include "knotholder.h" #include <glibmm/i18n.h> -// needed for on-canvas editting: -#include "desktop.h" - namespace Inkscape { namespace LivePathEffect { @@ -126,9 +123,8 @@ PointParam::param_newWidget() *param_wr, param_effect->getRepr(), param_effect->getSPDoc() ) ); - // TODO: fix to get correct desktop (don't use SP_ACTIVE_DESKTOP) - SPDesktop *desktop = SP_ACTIVE_DESKTOP; - Geom::Affine transf = desktop->doc2dt(); + Geom::Affine transf = Geom::Scale(1, -1); + transf[5] = SP_ACTIVE_DOCUMENT->getHeight().value("px"); _pointwdg->setTransform(transf); _pointwdg->setValue( *this ); _pointwdg->clearProgrammatically(); @@ -205,12 +201,12 @@ PointParamKnotHolderEntity::knot_click(guint state) } void -PointParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) +PointParam::addKnotHolderEntities(KnotHolder *knotholder, SPItem *item) { knoth = knotholder; PointParamKnotHolderEntity *e = new PointParamKnotHolderEntity(this); // TODO: can we ditch handleTip() etc. because we have access to handle_tip etc. itself??? - e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, handleTip(), knot_shape, knot_mode, knot_color); + e->create(NULL, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, handleTip(), knot_shape, knot_mode, knot_color); knotholder->add(e); } diff --git a/src/live_effects/parameter/point.h b/src/live_effects/parameter/point.h index 62c6fb83d..e8cb66225 100644 --- a/src/live_effects/parameter/point.h +++ b/src/live_effects/parameter/point.h @@ -49,7 +49,7 @@ public: void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color); virtual bool providesKnotHolderEntities() const { return true; } - virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); + virtual void addKnotHolderEntities(KnotHolder *knotholder, SPItem *item); friend class PointParamKnotHolderEntity; private: diff --git a/src/live_effects/parameter/powerstrokepointarray.cpp b/src/live_effects/parameter/powerstrokepointarray.cpp index c61e8f9cb..7753d819d 100644 --- a/src/live_effects/parameter/powerstrokepointarray.cpp +++ b/src/live_effects/parameter/powerstrokepointarray.cpp @@ -248,11 +248,11 @@ PowerStrokePointArrayParamKnotHolderEntity::knot_click(guint state) } } -void PowerStrokePointArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) +void PowerStrokePointArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPItem *item) { for (unsigned int i = 0; i < _vector.size(); ++i) { PowerStrokePointArrayParamKnotHolderEntity *e = new PowerStrokePointArrayParamKnotHolderEntity(this, i); - e->create( desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, + e->create(NULL, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _("<b>Stroke width control point</b>: drag to alter the stroke width. <b>Ctrl+click</b> adds a control point, <b>Ctrl+Alt+click</b> deletes it, <b>Shift+click</b> launches width dialog."), knot_shape, knot_mode, knot_color); knotholder->add(e); diff --git a/src/live_effects/parameter/powerstrokepointarray.h b/src/live_effects/parameter/powerstrokepointarray.h index 70b22e27e..56a609fa8 100644 --- a/src/live_effects/parameter/powerstrokepointarray.h +++ b/src/live_effects/parameter/powerstrokepointarray.h @@ -38,7 +38,7 @@ public: float median_width(); virtual bool providesKnotHolderEntities() const { return true; } - virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); + virtual void addKnotHolderEntities(KnotHolder *knotholder, SPItem *item); void set_pwd2(Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in, Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_normal_in); Geom::Piecewise<Geom::D2<Geom::SBasis> > const & get_pwd2() const { return last_pwd2; } diff --git a/src/live_effects/parameter/vector.cpp b/src/live_effects/parameter/vector.cpp index cfaa9e7e7..aa16a2b98 100644 --- a/src/live_effects/parameter/vector.cpp +++ b/src/live_effects/parameter/vector.cpp @@ -14,7 +14,6 @@ #include "svg/stringstream.h" #include "live_effects/effect.h" -#include "desktop.h" #include "verbs.h" namespace Inkscape { @@ -188,14 +187,14 @@ private: }; void -VectorParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) +VectorParam::addKnotHolderEntities(KnotHolder *knotholder, SPItem *item) { VectorParamKnotHolderEntity_Origin *origin_e = new VectorParamKnotHolderEntity_Origin(this); - origin_e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, handleTip(), ori_knot_shape, ori_knot_mode, ori_knot_color); + origin_e->create(NULL, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, handleTip(), ori_knot_shape, ori_knot_mode, ori_knot_color); knotholder->add(origin_e); VectorParamKnotHolderEntity_Vector *vector_e = new VectorParamKnotHolderEntity_Vector(this); - vector_e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, handleTip(), vec_knot_shape, vec_knot_mode, vec_knot_color); + vector_e->create(NULL, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, handleTip(), vec_knot_shape, vec_knot_mode, vec_knot_color); knotholder->add(vector_e); } diff --git a/src/live_effects/parameter/vector.h b/src/live_effects/parameter/vector.h index 35ca04437..edee4ff4d 100644 --- a/src/live_effects/parameter/vector.h +++ b/src/live_effects/parameter/vector.h @@ -53,7 +53,7 @@ public: void set_oncanvas_color(guint32 color); virtual bool providesKnotHolderEntities() const { return true; } - virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); + virtual void addKnotHolderEntities(KnotHolder *knotholder, SPItem *item); private: VectorParam(const VectorParam&); diff --git a/src/ui/object-edit.cpp b/src/ui/object-edit.cpp index 2763e6c4b..cf2c03396 100644 --- a/src/ui/object-edit.cpp +++ b/src/ui/object-edit.cpp @@ -43,7 +43,7 @@ static KnotHolder *sp_lpe_knot_holder(SPLPEItem *item, SPDesktop *desktop) KnotHolder *knot_holder = new KnotHolder(desktop, item, NULL); Inkscape::LivePathEffect::Effect *effect = item->getCurrentLPE(); - effect->addHandles(knot_holder, desktop, item); + effect->addHandles(knot_holder, item); return knot_holder; } diff --git a/src/ui/tool/node.cpp b/src/ui/tool/node.cpp index 0e5a9279d..d6e491ac3 100644 --- a/src/ui/tool/node.cpp +++ b/src/ui/tool/node.cpp @@ -326,10 +326,7 @@ bool Handle::grabbed(GdkEventMotion *) void Handle::dragged(Geom::Point &new_pos, GdkEventMotion *event) { - if (tools_isactive(_desktop, TOOLS_NODES)) { - Inkscape::UI::Tools::NodeTool *nt = static_cast<Inkscape::UI::Tools::NodeTool*>(_desktop->event_context); - nt->update_helperpath(); - } + Inkscape::UI::Tools::sp_update_helperpath(); Geom::Point parent_pos = _parent->position(); Geom::Point origin = _last_drag_origin(); SnapManager &sm = _desktop->namedview->snap_manager; @@ -1199,10 +1196,7 @@ bool Node::grabbed(GdkEventMotion *event) void Node::dragged(Geom::Point &new_pos, GdkEventMotion *event) { - if (tools_isactive(_desktop, TOOLS_NODES)) { - Inkscape::UI::Tools::NodeTool *nt = static_cast<Inkscape::UI::Tools::NodeTool*>(_desktop->event_context); - nt->update_helperpath(); - } + Inkscape::UI::Tools::sp_update_helperpath(); // For a note on how snapping is implemented in Inkscape, see snap.h. SnapManager &sm = _desktop->namedview->snap_manager; // even if we won't really snap, we might still call the one of the diff --git a/src/ui/tools/node-tool.cpp b/src/ui/tools/node-tool.cpp index f3679b40f..0c948c91c 100644 --- a/src/ui/tools/node-tool.cpp +++ b/src/ui/tools/node-tool.cpp @@ -32,6 +32,8 @@ #include "sp-text.h" #include "ui/control-manager.h" #include "ui/tools/node-tool.h" +#include "ui/tools-switch.h" +#include "ui/tools/tool-base.h" #include "ui/tool/control-point-selection.h" #include "ui/tool/event-utils.h" #include "ui/tool/multi-path-manipulator.h" @@ -209,7 +211,7 @@ void NodeTool::setup() { this->_sizeUpdatedConn = ControlManager::getManager().connectCtrlSizeChanged( sigc::mem_fun(this, &NodeTool::handleControlUiStyleChange) ); - + this->helperpath_tmpitem = NULL; this->_selected_nodes = new Inkscape::UI::ControlPointSelection(this->desktop, this->_transform_handle_group); data.node_data.selection = this->_selected_nodes; @@ -237,7 +239,6 @@ void NodeTool::setup() { ))) ); - this->helperpath_tmpitem = NULL; this->cursor_drag = false; this->show_transform_handles = true; this->single_node_transform_handles = false; @@ -270,29 +271,34 @@ void NodeTool::setup() { } this->desktop->emitToolSubselectionChanged(NULL); // sets the coord entry fields to inactive - this->update_helperpath(); + sp_update_helperpath(); } // show helper paths of the applied LPE, if any -void NodeTool::update_helperpath () { - Inkscape::Selection *selection = this->desktop->getSelection(); - - if (this->helperpath_tmpitem) { - this->desktop->remove_temporary_canvasitem(this->helperpath_tmpitem); - this->helperpath_tmpitem = NULL; +void sp_update_helperpath() { + SPDesktop * desktop = SP_ACTIVE_DESKTOP; + if (!desktop || !tools_isactive(desktop, TOOLS_NODES)) { + return; + } + Inkscape::UI::Tools::NodeTool *nt = static_cast<Inkscape::UI::Tools::NodeTool*>(desktop->event_context); + Inkscape::Selection *selection = desktop->getSelection(); + if (nt->helperpath_tmpitem) { + desktop->remove_temporary_canvasitem(nt->helperpath_tmpitem); + nt->helperpath_tmpitem = NULL; } if (SP_IS_LPE_ITEM(selection->singleItem())) { Inkscape::LivePathEffect::Effect *lpe = SP_LPE_ITEM(selection->singleItem())->getCurrentLPE(); if (lpe && lpe->isVisible()/* && lpe->showOrigPath()*/) { - Inkscape::UI::ControlPointSelection *selectionNodes = _selected_nodes; + + Inkscape::UI::ControlPointSelection *selectionNodes = nt->_selected_nodes; std::vector<Geom::Point> selectedNodesPositions; for (Inkscape::UI::ControlPointSelection::iterator i = selectionNodes->begin(); i != selectionNodes->end(); ++i) { Inkscape::UI::Node *n = dynamic_cast<Inkscape::UI::Node *>(*i); selectedNodesPositions.push_back(n->position()); } lpe->setSelectedNodePoints(selectedNodesPositions); - lpe->setCurrentZoom(this->desktop->current_zoom()); + lpe->setCurrentZoom(desktop->current_zoom()); SPCurve *c = new SPCurve(); SPCurve *cc = new SPCurve(); std::vector<Geom::PathVector> cs = lpe->getCanvasIndicators(SP_LPE_ITEM(selection->singleItem())); @@ -302,11 +308,11 @@ void NodeTool::update_helperpath () { cc->reset(); } if (!c->is_empty()) { - SPCanvasItem *helperpath = sp_canvas_bpath_new(this->desktop->getTempGroup(), c, true); + SPCanvasItem *helperpath = sp_canvas_bpath_new(desktop->getTempGroup(), c, true); sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(helperpath), 0x0000ff9A, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(helperpath), 0, SP_WIND_RULE_NONZERO); sp_canvas_item_affine_absolute(helperpath, selection->singleItem()->i2dt_affine()); - this->helperpath_tmpitem = this->desktop->add_temporary_canvasitem(helperpath, 0); + nt->helperpath_tmpitem = desktop->add_temporary_canvasitem(helperpath, 0); } c->unref(); cc->unref(); @@ -468,7 +474,7 @@ bool NodeTool::root_handler(GdkEvent* event) { switch (event->type) { case GDK_MOTION_NOTIFY: { - update_helperpath(); + sp_update_helperpath(); combine_motion_events(desktop->canvas, event->motion, 0); SPItem *over_item = sp_event_context_find_item (desktop, event_point(event->button), FALSE, TRUE); diff --git a/src/ui/tools/node-tool.h b/src/ui/tools/node-tool.h index 8342d66a6..983ba6cee 100644 --- a/src/ui/tools/node-tool.h +++ b/src/ui/tools/node-tool.h @@ -49,14 +49,14 @@ public: Inkscape::UI::ControlPointSelection* _selected_nodes; Inkscape::UI::MultiPathManipulator* _multipath; - + Inkscape::Display::TemporaryItem *helperpath_tmpitem; + bool edit_clipping_paths; bool edit_masks; static const std::string prefsPath; virtual void setup(); - virtual void update_helperpath(); virtual void set(const Inkscape::Preferences::Entry& val); virtual bool root_handler(GdkEvent* event); @@ -68,7 +68,7 @@ private: sigc::connection _sizeUpdatedConn; SPItem *flashed_item; - Inkscape::Display::TemporaryItem *helperpath_tmpitem; + Inkscape::Display::TemporaryItem *flash_tempitem; Inkscape::UI::Selector* _selector; Inkscape::UI::PathSharedData* _path_data; @@ -96,8 +96,9 @@ private: void update_tip(GdkEvent *event); void handleControlUiStyleChange(); }; - + void sp_update_helperpath(); } + } } |
