int main() { xorn_revision_t rev0, rev1, rev2; struct xornsch_line line_data; xorn_object_t ob; rev0 = xorn_new_revision(NULL); assert(rev0 != NULL); xorn_finalize_revision(rev0); rev1 = xorn_new_revision(rev0); assert(rev1 != NULL); memset(&line_data, 0, sizeof line_data); line_data.pos.x = 0; line_data.pos.y = 1; line_data.size.x = 3; line_data.size.y = 2; line_data.color = 3; line_data.line.width = 1; ob = xorn_add_object(rev1, xorn_obtype_none, &line_data); assert(ob == NULL); ob = xorn_add_object(rev1, xornsch_obtype_line, &line_data); assert(ob != NULL); xorn_finalize_revision(rev1); rev2 = xorn_new_revision(rev1); assert(rev2 != NULL); assert(xorn_set_object_data(rev2, ob, xorn_obtype_none, &line_data) == -1); assert(xorn_set_object_data(rev2, ob, xornsch_obtype_line, &line_data) == 0); xorn_finalize_revision(rev2); xorn_free_revision(rev2); xorn_free_revision(rev1); xorn_free_revision(rev0); return 0; }
static PyObject *Revision_set_object_data( Revision *self, PyObject *args, PyObject *kwds) { PyObject *ob_arg = NULL, *data_arg = NULL; static char *kwlist[] = { "ob", "data", NULL }; if (!PyArg_ParseTupleAndKeywords( args, kwds, "O!O:Revision.set_object_data", kwlist, &ObjectType, &ob_arg, &data_arg)) return NULL; if (!xorn_revision_is_transient(self->rev)) return not_transient(); xorn_obtype_t type = xorn_obtype_none; const void *data = NULL; if (prepare_data(data_arg, &type, &data) == -1) { char buf[BUFSIZ]; snprintf(buf, BUFSIZ, "Revision.set_object_data() argument 'data' (pos 2) " "must be of xorn.storage object type, not %.50s", data_arg->ob_type->tp_name); PyErr_SetString(PyExc_TypeError, buf); return NULL; } if (type != xornsch_obtype_text) { xorn_object_t attached_to; if (xorn_get_object_location(self->rev, ((Object *)ob_arg)->ob, &attached_to, NULL) != -1 && attached_to != NULL) { PyErr_SetString(PyExc_ValueError, "Cannot set attached object to " "something other than text"); return NULL; } } if (type != xornsch_obtype_net && type != xornsch_obtype_component) { size_t count; if (xorn_get_objects_attached_to( self->rev, ((Object *)ob_arg)->ob, NULL, &count) != -1 && count != 0) { PyErr_SetString( PyExc_ValueError, "Cannot set object with attached objects to " "something other than net or component"); return NULL; } } if (xorn_set_object_data(self->rev, ((Object *)ob_arg)->ob, type, data) == -1) return PyErr_NoMemory(); Py_INCREF(Py_None); return Py_None; }
int main(void) { xorn_revision_t rev; rev = xorn_new_revision(NULL); { /** [add object] */ struct xornsch_line line_data; memset(&line_data, 0, sizeof line_data); line_data.pos.x = 0; line_data.pos.y = 0; line_data.size.x = 100; line_data.size.y = 100; line_data.line.width = 1; xorn_object_t ob; ob = xorn_add_object(rev, xornsch_obtype_line, &line_data); if (ob == NULL) /* handle error */; /** [add object] */ /** [get object data] */ const struct xornsch_line *data; data = xorn_get_object_data(rev, ob, xornsch_obtype_line); if (data == NULL) /* ob doesn't exist or isn't a line */; /** [get object data] */ } { struct xornsch_net net_data; xorn_object_t ob; memset(&net_data, 0, sizeof net_data); ob = xornsch_add_net(rev, &net_data); /** [set object data] */ struct xornsch_line line_data; memset(&line_data, 0, sizeof line_data); line_data.pos.x = 0; line_data.pos.y = 0; line_data.size.x = 100; line_data.size.y = 100; line_data.line.width = 1; if (xorn_set_object_data(rev, ob, xornsch_obtype_line, &line_data) == -1) /* handle error */; /** [set object data] */ } { /** [get objects] */ xorn_object_t *objects; size_t count; unsigned int i; if (xorn_get_objects(rev, &objects, &count) == -1) /* handle error */; for (i = 0; i < count; i++) /* do something with objects[i] */; free(objects); /** [get objects] */ } { struct xornsch_component component_data; xorn_object_t component; memset(&component_data, 0, sizeof component_data); component = xornsch_add_component(rev, &component_data); /** [add attribute] */ struct xornsch_text text_data; memset(&text_data, 0, sizeof text_data); text_data.text.s = "refdes=R1"; text_data.text.len = strlen(text_data.text.s); xorn_object_t ob; ob = xornsch_add_text(rev, &text_data); if (ob == NULL) /* handle error */; if (xorn_relocate_object(rev, ob, component, NULL) == -1) /* handle error */; /** [add attribute] */ } xorn_free_revision(rev); return 0; }