1 /* Copyright (C) 2013-2020 Roland Lutz
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2 of the License, or
6 (at your option) any later version.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software Foundation,
15 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19 #include <xornstorage.h>
24 xorn_revision_t rev0
, rev1
, rev2
, rev3
;
25 xorn_object_t line
, box
, circle
;
28 struct xornsch_line line_data
;
29 struct xornsch_box box_data
;
30 struct xornsch_circle circle_data
;
31 struct xornsch_net net_data
;
34 /* Create an empty revision and make it read-only. */
36 rev0
= xorn_new_revision(NULL
);
41 xorn_finalize_revision(rev0
);
44 /* Copy the revision */
46 /* You could omit the previous step and just create an empty
47 revision if you don't need to refer to the empty state later. */
49 rev1
= xorn_new_revision(rev0
);
54 /* Prepare a xornsch_line structure */
56 memset(&line_data
, 0, sizeof line_data
);
62 line_data
.line
.width
= 1;
64 /* Add a line object with this data to the revision */
66 line
= xornsch_add_line(rev1
, &line_data
, &err
);
71 /* Finalize the revision */
73 xorn_finalize_revision(rev1
);
76 /* Create a copy of the last revision, add a box and a circle
77 to it, and finalize it */
79 rev2
= xorn_new_revision(rev1
);
83 memset(&box_data
, 0, sizeof box_data
);
89 box_data
.line
.width
= 1;
91 box
= xornsch_add_box(rev2
, &box_data
, &err
);
95 memset(&circle_data
, 0, sizeof circle_data
);
96 circle_data
.pos
.x
= -1;
97 circle_data
.pos
.y
= -1;
98 circle_data
.radius
= 2;
99 circle_data
.color
= 3;
100 circle_data
.line
.width
= 1;
101 circle_data
.fill
.type
= 1;
103 circle
= xornsch_add_circle(rev2
, &circle_data
, &err
);
107 xorn_finalize_revision(rev2
);
110 /* Create a copy of the last revision, set the line's object
111 type to net and change its color, delete the box, and
112 finalize the revision */
114 rev3
= xorn_new_revision(rev2
);
118 memset(&net_data
, 0, sizeof net_data
);
125 if (xornsch_set_net_data(rev3
, line
, &net_data
, &err
) == -1)
128 if (xorn_delete_object(rev3
, box
, &err
) == -1)
131 xorn_finalize_revision(rev3
);
134 /* ... you could do something with these revisions now ... */
137 /* Free the revisions (the order doesn't matter) */
139 xorn_free_revision(rev3
);
140 xorn_free_revision(rev2
);
141 xorn_free_revision(rev1
);
142 xorn_free_revision(rev0
);
144 /* No need to free objects */
149 xorn_free_revision(rev3
);
151 xorn_free_revision(rev2
);
153 xorn_free_revision(rev1
);
155 xorn_free_revision(rev0
);
157 fprintf(stderr
, "Out of memory\n");