X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fconn-avoid-ref.cpp;h=43c9c0b66cb652c5fa906f50d7d1f5e1c5ca20b2;hb=43be2ed2178db96177d31205e4b9692535612136;hp=d832a34b4b81491a31d3c9ea234cf1cbc3868090;hpb=3fea53c3e91bfe887e67441426326944d802bf68;p=inkscape.git diff --git a/src/conn-avoid-ref.cpp b/src/conn-avoid-ref.cpp index d832a34b4..43c9c0b66 100644 --- a/src/conn-avoid-ref.cpp +++ b/src/conn-avoid-ref.cpp @@ -10,23 +10,24 @@ */ +#include +#include #include "sp-item.h" #include "conn-avoid-ref.h" -#include "libnr/nr-rect-ops.h" #include "libavoid/polyutil.h" -#include "libavoid/incremental.h" +#include "libavoid/router.h" #include "libavoid/connector.h" -#include "xml/simple-node.cpp" +#include "xml/node.h" #include "document.h" -#include "prefs-utils.h" - #include "desktop.h" #include "desktop-handles.h" #include "sp-namedview.h" #include "inkscape.h" +using Avoid::Router; + static Avoid::Polygn avoid_item_poly(SPItem const *item); @@ -44,9 +45,10 @@ SPAvoidRef::~SPAvoidRef() { _transformed_connection.disconnect(); if (shapeRef) { + Router *router = shapeRef->router(); // shapeRef is finalised by delShape, // so no memory is lost here. - Avoid::delShape(shapeRef); + router->delShape(shapeRef); shapeRef = NULL; } } @@ -71,29 +73,41 @@ void SPAvoidRef::handleSettingChange(void) if (desktop == NULL) { return; } - + if (sp_desktop_document(desktop) != item->document) { + // We don't want to go any further if the active desktop's document + // isn't the same as the document that this item is part of. This + // case can happen if a new document is loaded from the file chooser + // or via the recent file menu. In this case, we can end up here + // as a rersult of a sp_document_ensure_up_to_date performed on a + // document not yet attached to the active desktop. + return; + } + if (new_setting == setting) { // Don't need to make any changes return; } + setting = new_setting; + Router *router = item->document->router; + _transformed_connection.disconnect(); if (new_setting) { - _transformed_connection = item->connectTransformed( - sigc::ptr_fun(&avoid_item_move)); - Avoid::Polygn poly = avoid_item_poly(item); if (poly.pn > 0) { + _transformed_connection = item->connectTransformed( + sigc::ptr_fun(&avoid_item_move)); + const char *id = SP_OBJECT_REPR(item)->attribute("id"); g_assert(id != NULL); // Get a unique ID for the item. GQuark itemID = g_quark_from_string(id); - shapeRef = new Avoid::ShapeRef(itemID, poly); + shapeRef = new Avoid::ShapeRef(router, itemID, poly); Avoid::freePoly(poly); - Avoid::addShape(shapeRef); + router->addShape(shapeRef); } } else @@ -102,10 +116,9 @@ void SPAvoidRef::handleSettingChange(void) // shapeRef is finalised by delShape, // so no memory is lost here. - Avoid::delShape(shapeRef); + router->delShape(shapeRef); shapeRef = NULL; } - setting = new_setting; } @@ -115,7 +128,7 @@ GSList *SPAvoidRef::getAttachedShapes(const unsigned int type) Avoid::IntList shapes; GQuark shapeId = g_quark_from_string(item->id); - Avoid::attachedShapes(shapes, shapeId, type); + item->document->router->attachedShapes(shapes, shapeId, type); Avoid::IntList::iterator finish = shapes.end(); for (Avoid::IntList::iterator i = shapes.begin(); i != finish; ++i) { @@ -139,7 +152,7 @@ GSList *SPAvoidRef::getAttachedConnectors(const unsigned int type) Avoid::IntList conns; GQuark shapeId = g_quark_from_string(item->id); - Avoid::attachedConns(conns, shapeId, type); + item->document->router->attachedConns(conns, shapeId, type); Avoid::IntList::iterator finish = conns.end(); for (Avoid::IntList::iterator i = conns.begin(); i != finish; ++i) { @@ -172,44 +185,27 @@ static Avoid::Polygn avoid_item_poly(SPItem const *item) // some convex hull code, though not NR::ConvexHull as this // only keeps the bounding box of the convex hull currently. - // TODO: SPItem::invokeBbox gives the wrong result for some objects + // TODO: SPItem::getBounds gives the wrong result for some objects // that have internal representations that are updated later // by the sp_*_update functions, e.g., text. sp_document_ensure_up_to_date(item->document); - NR::Rect rHull = item->invokeBbox(sp_item_i2doc_affine(item)); - + Geom::OptRect rHull = item->getBounds(sp_item_i2doc_affine(item)); + if (!rHull) { + return Avoid::newPoly(0); + } double spacing = desktop->namedview->connector_spacing; // Add a little buffer around the edge of each object. - NR::Rect rExpandedHull = NR::expand(rHull, -spacing); + Geom::Rect rExpandedHull = *rHull; + rExpandedHull.expandBy(spacing); poly = Avoid::newPoly(4); for (unsigned n = 0; n < 4; ++n) { - // TODO: I think the winding order in libavoid or inkscape might - // be backwards, probably due to the inverse y co-ordinates - // used for the screen. The '3 - n' reverses the order. - /* On "correct" winding order: Winding order of NR::Rect::corner is in a positive - * direction, like libart. "Positive direction" means the same as in most of Inkscape and - * SVG: if you visualize y as increasing upwards, as is the convention in mathematics, then - * positive angle is visualized as anticlockwise, as in mathematics; so if you visualize y - * as increasing downwards, as is common outside of mathematics, then positive angle - * direction is visualized as clockwise, as is common outside of mathematics. This - * convention makes it easier mix pure mathematics code with graphics code: the important - * thing when mixing code is that the number values stored in variables (representing y - * coordinate, angle) match up; variables store numbers, not visualized positions, and the - * programmer is free to switch between visualizations when thinking about a given piece of - * code. - * - * MathWorld, libart and NR::Rect::corner all seem to take positive winding (i.e. winding - * that yields +1 winding number inside a simple closed shape) to mean winding in a - * positive angle. This, together with the observation that variables store numbers rather - * than positions, suggests that NR::Rect::corner uses the right direction. - */ - NR::Point hullPoint = rExpandedHull.corner(3 - n); - poly.ps[n].x = hullPoint[NR::X]; - poly.ps[n].y = hullPoint[NR::Y]; + Geom::Point hullPoint = rExpandedHull.corner(n); + poly.ps[n].x = hullPoint[Geom::X]; + poly.ps[n].y = hullPoint[Geom::Y]; } return poly; @@ -240,15 +236,15 @@ GSList *get_avoided_items(GSList *list, SPObject *from, SPDesktop *desktop, } -void avoid_item_move(NR::Matrix const *mp, SPItem *moved_item) +void avoid_item_move(Geom::Matrix const */*mp*/, SPItem *moved_item) { Avoid::ShapeRef *shapeRef = moved_item->avoidRef->shapeRef; g_assert(shapeRef); + Router *router = moved_item->document->router; Avoid::Polygn poly = avoid_item_poly(moved_item); if (poly.pn > 0) { - // moveShape actually destroys the old shapeRef and returns a new one. - moved_item->avoidRef->shapeRef = Avoid::moveShape(shapeRef, &poly); + router->moveShape(shapeRef, &poly); Avoid::freePoly(poly); } } @@ -257,10 +253,10 @@ void avoid_item_move(NR::Matrix const *mp, SPItem *moved_item) void init_avoided_shape_geometry(SPDesktop *desktop) { // Don't count this as changes to the document, - // it is basically just llate initialisation. - SPDocument *document = SP_DT_DOCUMENT(desktop); - gboolean saved = sp_document_get_undo_sensitive(document); - sp_document_set_undo_sensitive(document, FALSE); + // it is basically just late initialisation. + SPDocument *document = sp_desktop_document(desktop); + bool saved = sp_document_get_undo_sensitive(document); + sp_document_set_undo_sensitive(document, false); bool initialised = false; GSList *items = get_avoided_items(NULL, desktop->currentRoot(), desktop,