From 913cb932fefc97f72cc834beb4129f833ccdd25a Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 22 Oct 2015 08:25:32 +0200 Subject: improving spray tool (bzr r14422.2.1) --- src/ui/tools/spray-tool.cpp | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index 240d002ae..c6448f818 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -57,6 +57,9 @@ #include "livarot/Shape.h" #include <2geom/circle.h> #include <2geom/transforms.h> +#include <2geom/path-intersection.h> +#include <2geom/pathvector.h> +#include <2geom/crossing.h> #include "preferences.h" #include "style.h" #include "box3d.h" @@ -380,7 +383,10 @@ static bool sp_spray_recursive(SPDesktop *desktop, Inkscape::XML::Node *old_repr = item->getRepr(); Inkscape::XML::Node *parent = old_repr->parent(); Inkscape::XML::Node *copy = old_repr->duplicate(xml_doc); - copy->setAttribute("inkscape:spray-origin", item->getId()); + std::stringstream original_id; + original_id << "#" << item->getId(); + gchar const * spray_origin = original_id.str().c_str()); + copy->setAttribute("inkscape:spray-origin", spray_origin); parent->appendChild(copy); SPObject *new_obj = doc->getObjectByRepr(copy); @@ -394,44 +400,46 @@ static bool sp_spray_recursive(SPDesktop *desktop, Geom::Point move = (Geom::Point(cos(tilt)*cos(dp)*dr/(1-ratio)+sin(tilt)*sin(dp)*dr/(1+ratio), -sin(tilt)*cos(dp)*dr/(1-ratio)+cos(tilt)*sin(dp)*dr/(1+ratio)))+(p-a->midpoint()); sp_item_move_rel(item_copied, Geom::Translate(move[Geom::X], -move[Geom::Y])); did = true; - Geom::OptRect bbox = item_copied->desktopGeometricBounds(); + Geom::OptRect bbox = item_copied->documentVisualBounds(); std::vector items = desktop->getDocument()->getItemsInBox(desktop->dkey, *bbox); for (std::vector::const_iterator i=items.begin(); i!=items.end(); i++) { SPItem *item_down = *i; std::cout << item_down->getAttribute("inkscape:spray-origin") << "asdgfasdasas\n"; - if(item_down->getAttribute("inkscape:spray-origin") &&( strcmp(item_down->getAttribute("inkscape:spray-origin"),item->getId()) == 0 || strcmp(item_down->getId(),item->getId()) == 0)){ + if(item_down->getAttribute("inkscape:spray-origin") &&( strcmp(item_down->getAttribute("inkscape:spray-origin"),spray_origin) == 0 || strcmp(item_down->getId(),item->getId()) == 0)){ if(!SP_IS_GROUP(item)){ SPShape *down_item_shape = dynamic_cast(item_down); if (down_item_shape) { - Geom::PathVector c; + Geom::PathVector pathv; SPPath *down_item_path = dynamic_cast(down_item_shape); if (down_item_path) { - c = down_item_path->get_curve()->get_pathvector(); + pathv = down_item_path->get_curve()->get_pathvector(); } else { - c = down_item_shape->getCurve()->get_pathvector(); + pathv = down_item_shape->getCurve()->get_pathvector(); } - if (c) { + if (!pathv.empty()) { SPShape *copied_item_shape = dynamic_cast(item_copied); if (copied_item_shape) { - Geom::PathVector d; + Geom::PathVector pathv_other; SPPath *copied_item_path = dynamic_cast(copied_item_shape); if (copied_item_path) { - d = copied_item_path->get_curve()->get_pathvector(); + pathv_other = copied_item_path->get_curve()->get_pathvector(); } else { - d = copied_item_shape->getCurve()->get_pathvector(); + pathv_other = copied_item_shape->getCurve()->get_pathvector(); } - if (d) { - Geom::CrossingSet cs = Geom::crossings(c,d); + if (!pathv_other.empty()) { + Geom::CrossingSet cs = Geom::crossings(pathv, pathv_other); if(cs[0].size() == 0){ continue; } } + } } } } item_copied->deleteObject(); std::cout << item_down->getAttribute("inkscape:spray-origin") << "hasssss\n"; did = false; + break; } } } -- cgit v1.2.3