sp-conn-end.cpp revision e7333a0a54c8d33b7397406dd76938aa430836d5
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);
6e16a663ee96cd1329e48518138efb415046d9f6mcecchettistatic SPObject const *
6e16a663ee96cd1329e48518138efb415046d9f6mcecchettiget_nearest_common_ancestor(SPObject const *const obj, SPItem const *const objs[2]) {
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti for (unsigned i = 0; i < 2; ++i) {
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti anc_sofar = anc_sofar->nearestCommonAncestor(objs[i]);
6e16a663ee96cd1329e48518138efb415046d9f6mcecchettisp_conn_end_move_compensate(NR::Matrix const */*mp*/, SPItem */*moved_item*/,
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti bool const updatePathRepr = true)
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 // Get the new route around obstacles.
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti path->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti SPObject const *const ancestor = get_nearest_common_ancestor(path_item, h2attItem);
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti NR::Matrix const path2anc(i2anc_affine(path_item, ancestor));
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti if (h2attItem[0] != NULL && h2attItem[1] != NULL) {
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti /* Initial end-points: centre of attached object. */
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti for (unsigned h = 0; h < 2; ++h) {
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti NR::Maybe<NR::Rect> bbox = h2attItem[h]->getBounds(NR::identity());
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti path->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti h2i2anc[h] = i2anc_affine(h2attItem[h], ancestor);
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti h2endPt_icoordsys[h] = h2bbox_icoordsys[h].midpoint();
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti // For each attached object, change the corresponding point to be
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti // on the edge of the bbox.
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti for (unsigned h = 0; h < 2; ++h) {
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti h2endPt_icoordsys[h] = calc_bbox_conn_pt(h2bbox_icoordsys[h],
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti h2endPt_pcoordsys[h] = h2endPt_icoordsys[h] * h2i2anc[h] / path2anc;
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 last_seg_pt = sp_curve_second_point(path->curve);
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti last_seg_pt = sp_curve_penultimate_point(path->curve);
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 path->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti h2i2anc = i2anc_affine(h2attItem[ind], ancestor);
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti h2endPt_icoordsys[ind] = h2bbox_icoordsys[ind].midpoint();
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti // For the attached object, change the corresponding point to be
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti // on the edge of the bbox.
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti h2endPt_icoordsys[ind] = calc_bbox_conn_pt(h2bbox_icoordsys[ind],
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti h2endPt_pcoordsys[ind] = h2endPt_icoordsys[ind] * h2i2anc / path2anc;
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti // Leave the other where it is.
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti path->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti// TODO: This triggering of makeInvalidPath could be cleaned up to be
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti// another option passed to move_compensate.
6e16a663ee96cd1329e48518138efb415046d9f6mcecchettisp_conn_end_shape_move_compensate(NR::Matrix const *mp, SPItem *moved_item,
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti sp_conn_end_move_compensate(mp, moved_item, path);
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);
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetticalc_bbox_conn_pt(NR::Rect const &bbox, NR::Point const &p)
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti if ( ctr == p ) {
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti /* Arbitrarily choose centre of right edge. */
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti NR::Dim2 const edgeDim = ( ( fabs(lengths[Y] * cp[X]) <
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti g_assert((offset[otherDim] >= 0) == (cp[otherDim] >= 0));
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti for (unsigned d = 0; d < 2; ++d) {
6e16a663ee96cd1329e48518138efb415046d9f6mcecchettistatic double signed_one(double const x)
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti return (x < 0
6e16a663ee96cd1329e48518138efb415046d9f6mcecchettichange_endpts(SPCurve *const curve, NR::Point const h2endPt[2])
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti sp_curve_move_endpoints(curve, h2endPt[0], h2endPt[1]);
6e16a663ee96cd1329e48518138efb415046d9f6mcecchettisp_conn_end_deleted(SPObject *, SPObject *const owner, unsigned const handle_ix)
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti // todo: The first argument is the deleted object, or just NULL if
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti // called by sp_conn_end_detach.
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti char const *const attr_str[] = {"inkscape:connection-start",
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti "inkscape:connection-end"};
if (value) {
* http://www.w3.org/TR/SVG11/implnote.html#ErrorProcessing. (Also needed for
if (refobj) {
path));