sp-conn-end.cpp revision e7333a0a54c8d33b7397406dd76938aa430836d5
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti#include "display/curve.h"
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti#include "libnr/nr-matrix-div.h"
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti#include "libnr/nr-matrix-fns.h"
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti#include "xml/repr.h"
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti#include "sp-conn-end.h"
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti#include "sp-path.h"
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti#include "uri.h"
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti#include "document.h"
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti
6e16a663ee96cd1329e48518138efb415046d9f6mcecchettistatic void change_endpts(SPCurve *const curve, NR::Point const h2endPt[2]);
6e16a663ee96cd1329e48518138efb415046d9f6mcecchettistatic NR::Point calc_bbox_conn_pt(NR::Rect const &bbox, NR::Point const &p);
6e16a663ee96cd1329e48518138efb415046d9f6mcecchettistatic double signed_one(double const x);
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti
6e16a663ee96cd1329e48518138efb415046d9f6mcecchettiSPConnEnd::SPConnEnd(SPObject *const owner) :
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti ref(owner),
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti href(NULL),
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti _changed_connection(),
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti _delete_connection(),
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti _transformed_connection()
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti{
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti}
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti
6e16a663ee96cd1329e48518138efb415046d9f6mcecchettistatic SPObject const *
6e16a663ee96cd1329e48518138efb415046d9f6mcecchettiget_nearest_common_ancestor(SPObject const *const obj, SPItem const *const objs[2]) {
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti SPObject const *anc_sofar = obj;
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti for (unsigned i = 0; i < 2; ++i) {
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti if ( objs[i] != NULL ) {
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti anc_sofar = anc_sofar->nearestCommonAncestor(objs[i]);
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti }
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti }
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti return anc_sofar;
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti}
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti
6e16a663ee96cd1329e48518138efb415046d9f6mcecchettistatic void
6e16a663ee96cd1329e48518138efb415046d9f6mcecchettisp_conn_end_move_compensate(NR::Matrix const */*mp*/, SPItem */*moved_item*/,
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti SPPath *const path,
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti bool const updatePathRepr = true)
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti{
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti // TODO: SPItem::getBounds gives the wrong result for some objects
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti // that have internal representations that are updated later
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti // by the sp_*_update functions, e.g., text.
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti sp_document_ensure_up_to_date(path->document);
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti // Get the new route around obstacles.
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti path->connEndPair.reroutePath();
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti SPItem *h2attItem[2];
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti path->connEndPair.getAttachedItems(h2attItem);
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti if ( !h2attItem[0] && !h2attItem[1] ) {
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti if (updatePathRepr) {
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti path->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti path->updateRepr();
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti }
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti return;
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti }
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti SPItem const *const path_item = SP_ITEM(path);
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti SPObject const *const ancestor = get_nearest_common_ancestor(path_item, h2attItem);
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti NR::Matrix const path2anc(i2anc_affine(path_item, ancestor));
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti if (h2attItem[0] != NULL && h2attItem[1] != NULL) {
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti /* Initial end-points: centre of attached object. */
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti NR::Point h2endPt_icoordsys[2];
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti NR::Matrix h2i2anc[2];
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti NR::Rect h2bbox_icoordsys[2];
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti NR::Point last_seg_endPt[2] = {
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti sp_curve_second_point(path->curve),
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti sp_curve_penultimate_point(path->curve)
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti };
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti for (unsigned h = 0; h < 2; ++h) {
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti NR::Maybe<NR::Rect> bbox = h2attItem[h]->getBounds(NR::identity());
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti if (!bbox) {
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti if (updatePathRepr) {
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti path->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti path->updateRepr();
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti }
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti return;
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti }
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti h2bbox_icoordsys[h] = *bbox;
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti h2i2anc[h] = i2anc_affine(h2attItem[h], ancestor);
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti h2endPt_icoordsys[h] = h2bbox_icoordsys[h].midpoint();
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti }
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti // For each attached object, change the corresponding point to be
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti // on the edge of the bbox.
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti NR::Point h2endPt_pcoordsys[2];
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti for (unsigned h = 0; h < 2; ++h) {
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti h2endPt_icoordsys[h] = calc_bbox_conn_pt(h2bbox_icoordsys[h],
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti ( last_seg_endPt[h] / h2i2anc[h] ));
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti h2endPt_pcoordsys[h] = h2endPt_icoordsys[h] * h2i2anc[h] / path2anc;
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti }
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti change_endpts(path->curve, h2endPt_pcoordsys);
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti } else {
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti // We leave the unattached endpoint where it is, and adjust the
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti // position of the attached endpoint to be on the edge of the bbox.
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti unsigned ind;
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti NR::Point other_endpt;
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti NR::Point last_seg_pt;
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti if (h2attItem[0] != NULL) {
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti other_endpt = sp_curve_last_point(path->curve);
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti last_seg_pt = sp_curve_second_point(path->curve);
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti ind = 0;
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti }
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti else {
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti other_endpt = sp_curve_first_point(path->curve);
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti last_seg_pt = sp_curve_penultimate_point(path->curve);
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti ind = 1;
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti }
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti NR::Point h2endPt_icoordsys[2];
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti NR::Matrix h2i2anc;
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti NR::Rect otherpt_rect = NR::Rect(other_endpt, other_endpt);
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti NR::Rect h2bbox_icoordsys[2] = { otherpt_rect, otherpt_rect };
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti NR::Maybe<NR::Rect> bbox = h2attItem[ind]->getBounds(NR::identity());
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti if (!bbox) {
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti if (updatePathRepr) {
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti path->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti path->updateRepr();
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti }
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti return;
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti }
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti h2bbox_icoordsys[ind] = *bbox;
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti h2i2anc = i2anc_affine(h2attItem[ind], ancestor);
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti h2endPt_icoordsys[ind] = h2bbox_icoordsys[ind].midpoint();
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti h2endPt_icoordsys[!ind] = other_endpt;
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti // For the attached object, change the corresponding point to be
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti // on the edge of the bbox.
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti NR::Point h2endPt_pcoordsys[2];
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti h2endPt_icoordsys[ind] = calc_bbox_conn_pt(h2bbox_icoordsys[ind],
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti ( last_seg_pt / h2i2anc ));
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti h2endPt_pcoordsys[ind] = h2endPt_icoordsys[ind] * h2i2anc / path2anc;
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti // Leave the other where it is.
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti h2endPt_pcoordsys[!ind] = other_endpt;
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti change_endpts(path->curve, h2endPt_pcoordsys);
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti }
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti if (updatePathRepr) {
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti path->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti path->updateRepr();
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti }
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti}
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti// TODO: This triggering of makeInvalidPath could be cleaned up to be
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti// another option passed to move_compensate.
6e16a663ee96cd1329e48518138efb415046d9f6mcecchettistatic void
6e16a663ee96cd1329e48518138efb415046d9f6mcecchettisp_conn_end_shape_move_compensate(NR::Matrix const *mp, SPItem *moved_item,
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti SPPath *const path)
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti{
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti if (path->connEndPair.isAutoRoutingConn()) {
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti path->connEndPair.makePathInvalid();
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti }
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti sp_conn_end_move_compensate(mp, moved_item, path);
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti}
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti
6e16a663ee96cd1329e48518138efb415046d9f6mcecchettivoid
6e16a663ee96cd1329e48518138efb415046d9f6mcecchettisp_conn_adjust_invalid_path(SPPath *const path)
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti{
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti sp_conn_end_move_compensate(NULL, NULL, path);
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti}
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti
6e16a663ee96cd1329e48518138efb415046d9f6mcecchettivoid
6e16a663ee96cd1329e48518138efb415046d9f6mcecchettisp_conn_adjust_path(SPPath *const path)
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti{
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti if (path->connEndPair.isAutoRoutingConn()) {
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti path->connEndPair.makePathInvalid();
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti }
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti // Don't update the path repr or else connector dragging is slowed by
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti // constant update of values to the xml editor, and each step is also
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti // needlessly remembered by undo/redo.
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti bool const updatePathRepr = false;
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti sp_conn_end_move_compensate(NULL, NULL, path, updatePathRepr);
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti}
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti
6e16a663ee96cd1329e48518138efb415046d9f6mcecchettistatic NR::Point
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetticalc_bbox_conn_pt(NR::Rect const &bbox, NR::Point const &p)
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti{
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti using NR::X;
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti using NR::Y;
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti NR::Point const ctr(bbox.midpoint());
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti NR::Point const lengths(bbox.dimensions());
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti if ( ctr == p ) {
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti /* Arbitrarily choose centre of right edge. */
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti return NR::Point(ctr[X] + .5 * lengths[X],
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti ctr[Y]);
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti }
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti NR::Point const cp( p - ctr );
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti NR::Dim2 const edgeDim = ( ( fabs(lengths[Y] * cp[X]) <
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti fabs(lengths[X] * cp[Y]) )
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti ? Y
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti : X );
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti NR::Dim2 const otherDim = (NR::Dim2) !edgeDim;
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti NR::Point offset;
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti offset[edgeDim] = (signed_one(cp[edgeDim])
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti * lengths[edgeDim]);
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti offset[otherDim] = (lengths[edgeDim]
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti * cp[otherDim]
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti / fabs(cp[edgeDim]));
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti g_assert((offset[otherDim] >= 0) == (cp[otherDim] >= 0));
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti#ifndef NDEBUG
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti for (unsigned d = 0; d < 2; ++d) {
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti g_assert(fabs(offset[d]) <= lengths[d] + .125);
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti }
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti#endif
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti return ctr + .5 * offset;
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti}
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti
6e16a663ee96cd1329e48518138efb415046d9f6mcecchettistatic double signed_one(double const x)
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti{
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti return (x < 0
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti ? -1.
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti : 1.);
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti}
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti
6e16a663ee96cd1329e48518138efb415046d9f6mcecchettistatic void
6e16a663ee96cd1329e48518138efb415046d9f6mcecchettichange_endpts(SPCurve *const curve, NR::Point const h2endPt[2])
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti{
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti#if 0
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti sp_curve_reset(curve);
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti sp_curve_moveto(curve, h2endPt[0]);
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti sp_curve_lineto(curve, h2endPt[1]);
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti#else
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti sp_curve_move_endpoints(curve, h2endPt[0], h2endPt[1]);
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti#endif
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti}
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti
6e16a663ee96cd1329e48518138efb415046d9f6mcecchettistatic void
6e16a663ee96cd1329e48518138efb415046d9f6mcecchettisp_conn_end_deleted(SPObject *, SPObject *const owner, unsigned const handle_ix)
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti{
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti // todo: The first argument is the deleted object, or just NULL if
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti // called by sp_conn_end_detach.
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti g_return_if_fail(handle_ix < 2);
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti char const *const attr_str[] = {"inkscape:connection-start",
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti "inkscape:connection-end"};
SP_OBJECT_REPR(owner)->setAttribute(attr_str[handle_ix], NULL);
/* I believe this will trigger sp_conn_end_href_changed. */
}
void
sp_conn_end_detach(SPObject *const owner, unsigned const handle_ix)
{
sp_conn_end_deleted(NULL, owner, handle_ix);
}
void
SPConnEnd::setAttacherHref(gchar const *value)
{
if ( value && href && ( strcmp(value, href) == 0 ) ) {
/* No change, do nothing. */
} else {
g_free(href);
href = NULL;
if (value) {
// First, set the href field, because sp_conn_end_href_changed will need it.
href = g_strdup(value);
// Now do the attaching, which emits the changed signal.
try {
ref.attach(Inkscape::URI(value));
} catch (Inkscape::BadURIException &e) {
/* TODO: Proper error handling as per
* http://www.w3.org/TR/SVG11/implnote.html#ErrorProcessing. (Also needed for
* sp-use.) */
g_warning("%s", e.what());
ref.detach();
}
} else {
ref.detach();
}
}
}
void
sp_conn_end_href_changed(SPObject */*old_ref*/, SPObject */*ref*/,
SPConnEnd *connEndPtr, SPPath *const path, unsigned const handle_ix)
{
g_return_if_fail(connEndPtr != NULL);
SPConnEnd &connEnd = *connEndPtr;
connEnd._delete_connection.disconnect();
connEnd._transformed_connection.disconnect();
if (connEnd.href) {
SPObject *refobj = connEnd.ref.getObject();
if (refobj) {
connEnd._delete_connection
= SP_OBJECT(refobj)->connectDelete(sigc::bind(sigc::ptr_fun(&sp_conn_end_deleted),
SP_OBJECT(path), handle_ix));
connEnd._transformed_connection
= SP_ITEM(refobj)->connectTransformed(sigc::bind(sigc::ptr_fun(&sp_conn_end_shape_move_compensate),
path));
}
}
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :