/** Find a connectionpoint sufficiently close to the given point. * * @param ddisp The display to search * @param pos A position in the display, typically mouse position * @param notthis If not null, an object to ignore (typically the object * connecting) * @param snap_to_objects Whether snapping to objects should be in effect * in this call (anded to the display-wide setting). */ ConnectionPoint * object_find_connectpoint_display(DDisplay *ddisp, Point *pos, DiaObject *notthis, gboolean snap_to_objects) { real distance; ConnectionPoint *connectionpoint; GList *avoid = NULL; DiaObject *obj_here; distance = diagram_find_closest_connectionpoint(ddisp->diagram, &connectionpoint, pos, notthis); distance = ddisplay_transform_length(ddisp, distance); if (distance < OBJECT_CONNECT_DISTANCE) { return connectionpoint; } if (ddisp->mainpoint_magnetism && snap_to_objects) { DiaObject *parent; /* Try to find an all-object CP. */ /* Don't pick a parent, though */ avoid = g_list_prepend(avoid, notthis); for (parent = notthis->parent; parent != NULL; parent = parent->parent) { avoid = g_list_prepend(avoid, parent); } obj_here = diagram_find_clicked_object_except(ddisp->diagram, pos, 0.00001, avoid); if (obj_here != NULL) { int i; for (i = 0; i < dia_object_get_num_connections(obj_here); ++i) { if (obj_here->connections[i]->flags & CP_FLAG_ANYPLACE) { g_list_free(avoid); return obj_here->connections[i]; } } } } return NULL; }
static PyObject * PyDiaDiagram_FindClosestConnectionPoint(PyDiaDiagram *self, PyObject *args) { Point p; double dist; ConnectionPoint *cpoint; PyObject *ret; PyDiaObject *obj = NULL; if (!PyArg_ParseTuple(args, "dd|O!:Diagram.find_closest_connectionpoint", &p.x, &p.y, PyDiaObject_Type, &obj)) return NULL; dist = diagram_find_closest_connectionpoint(self->dia, &cpoint, &p, obj ? obj->object : NULL); ret = PyTuple_New(2); PyTuple_SetItem(ret, 0, PyFloat_FromDouble(dist)); if (cpoint) PyTuple_SetItem(ret, 1, PyDiaConnectionPoint_New(cpoint)); else { Py_INCREF(Py_None); PyTuple_SetItem(ret, 1, Py_None); } return ret; }