Xorn
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
xornstorage.h
Go to the documentation of this file.
1 /* Copyright (C) 2013-2016 Roland Lutz
2 
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.
7 
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.
12 
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. */
16 
17 #ifndef XORN_STORAGE_H
18 #define XORN_STORAGE_H
19 
20 #include <stddef.h>
21 #include <stdbool.h>
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 typedef enum {
28  xorn_obtype_none, /* object does not exist */
39 
40 typedef enum {
42  /* None of the selected objects has this attribute.
43  Don't show this attribute in the property editor. */
45  /* All selected objects have the same value of this attribute.
46  Show this value for this attribute in the property editor. */
48  /* There are different values of this attribute between the
49  selected objects. Show this attribute in the property
50  editor, but don't show a value. */
51 } xorn_attst_t;
52 
53 /* opaque types */
54 typedef struct xorn_revision *xorn_revision_t;
55 typedef struct xorn_object *xorn_object_t;
56 typedef struct xorn_selection *xorn_selection_t;
57 
58 /* revision functions */
59 
60 xorn_revision_t xorn_new_revision(xorn_revision_t rev);
61 bool xorn_revision_is_transient(xorn_revision_t rev);
62 void xorn_finalize_revision(xorn_revision_t rev);
63 void xorn_free_revision(xorn_revision_t rev);
64 
65 /* object functions */
66 
68  xorn_revision_t rev, xorn_object_t ob);
70  xorn_revision_t rev, xorn_object_t ob);
71 const void *xorn_get_object_data(
72  xorn_revision_t rev, xorn_object_t ob, xorn_obtype_t type);
74  xorn_revision_t rev, xorn_object_t ob,
75  xorn_object_t *attached_to_return,
76  unsigned int *position_return);
77 
79  xorn_revision_t rev,
80  xorn_object_t **objects_return, size_t *count_return);
82  xorn_revision_t rev, xorn_object_t ob,
83  xorn_object_t **objects_return, size_t *count_return);
85  xorn_revision_t rev, xorn_selection_t sel,
86  xorn_object_t **objects_return, size_t *count_return);
88  xorn_revision_t from_rev, xorn_revision_t to_rev,
89  xorn_object_t **objects_return, size_t *count_return);
91  xorn_revision_t from_rev, xorn_revision_t to_rev,
92  xorn_object_t **objects_return, size_t *count_return);
94  xorn_revision_t from_rev, xorn_revision_t to_rev,
95  xorn_object_t **objects_return, size_t *count_return);
96 
97 /* selection functions */
98 
99 xorn_selection_t xorn_select_none();
100 xorn_selection_t xorn_select_object(
101  xorn_object_t ob);
102 xorn_selection_t xorn_select_attached_to(
103  xorn_revision_t rev, xorn_object_t ob);
104 xorn_selection_t xorn_select_all(
105  xorn_revision_t rev);
106 xorn_selection_t xorn_select_all_except(
107  xorn_revision_t rev, xorn_selection_t sel);
108 xorn_selection_t xorn_select_including(
109  xorn_selection_t sel, xorn_object_t ob);
110 xorn_selection_t xorn_select_excluding(
111  xorn_selection_t sel, xorn_object_t ob);
112 xorn_selection_t xorn_select_union(
113  xorn_selection_t sel0, xorn_selection_t sel1);
114 xorn_selection_t xorn_select_intersection(
115  xorn_selection_t sel0, xorn_selection_t sel1);
116 xorn_selection_t xorn_select_difference(
117  xorn_selection_t sel0, xorn_selection_t sel1);
118 
120  xorn_revision_t rev, xorn_selection_t sel);
122  xorn_revision_t rev, xorn_selection_t sel, xorn_object_t ob);
124  xorn_selection_t sel);
125 
126 /* manipulation functions */
127 
128 xorn_object_t xorn_add_object(xorn_revision_t rev,
129  xorn_obtype_t type, const void *data);
130 int xorn_set_object_data(xorn_revision_t rev, xorn_object_t ob,
131  xorn_obtype_t type, const void *data);
132 int xorn_relocate_object(xorn_revision_t rev, xorn_object_t ob,
133  xorn_object_t attach_to, xorn_object_t insert_before);
134 void xorn_delete_object(xorn_revision_t rev, xorn_object_t ob);
135 void xorn_delete_selected_objects(xorn_revision_t rev,
136  xorn_selection_t sel);
137 
138 xorn_object_t xorn_copy_object(xorn_revision_t dest,
139  xorn_revision_t src, xorn_object_t ob);
140 xorn_selection_t xorn_copy_objects(xorn_revision_t dest,
141  xorn_revision_t src, xorn_selection_t sel);
142 
143 /* object data definition */
144 
145 struct xorn_string {
146  const char *s;
147  size_t len;
148 };
149 
151  double x, y;
152 };
153 
154 struct xorn_pointer {
155  void *ptr;
156  void (*incref)(void *ptr);
157  void (*decref)(void *ptr);
158 };
159 
161  double width;
164  double dash_length;
165  double dash_space;
166 };
167 
169  int type;
170  double width;
171  int angle0;
172  double pitch0;
173  int angle1;
174  double pitch1;
175 };
176 
177 struct xornsch_arc {
179  double radius;
182  int color;
184 };
185 
186 struct xornsch_box {
189  int color;
192 };
193 
196  double radius;
197  int color;
200 };
201 
205  int angle;
206  bool mirror;
208 };
209 
210 struct xornsch_line {
213  int color;
215 };
216 
217 struct xornsch_net {
220  int color;
221  bool is_bus;
222  bool is_pin;
224 };
225 
226 struct xornsch_path {
228  int color;
231 };
232 
236  int angle;
237  bool mirror;
239 };
240 
241 struct xornsch_text {
243  int color;
247  int angle;
250 };
251 
252 /* object type-specific functions */
253 
254 #define DECLARE_OBJECT_FUNCTIONS(type) \
255  const struct xornsch_##type *xornsch_get_##type##_data( \
256  xorn_revision_t rev, xorn_object_t ob); \
257  xorn_object_t xornsch_add_##type(xorn_revision_t rev, \
258  const struct xornsch_##type *data); \
259  int xornsch_set_##type##_data(xorn_revision_t rev, xorn_object_t ob, \
260  const struct xornsch_##type *data);
261 
262 DECLARE_OBJECT_FUNCTIONS(arc)
263 DECLARE_OBJECT_FUNCTIONS(box)
264 DECLARE_OBJECT_FUNCTIONS(circle)
265 DECLARE_OBJECT_FUNCTIONS(component)
266 DECLARE_OBJECT_FUNCTIONS(line)
267 DECLARE_OBJECT_FUNCTIONS(net)
268 DECLARE_OBJECT_FUNCTIONS(path)
269 DECLARE_OBJECT_FUNCTIONS(picture)
270 DECLARE_OBJECT_FUNCTIONS(text)
271 
272 #undef DECLARE_OBJECT_FUNCTIONS
273 
274 /* attribute functions */
275 
276 #define DECLARE_ATTRIBUTE_FUNCTIONS(ns, name, intype, outtype) \
277  void ns##_get_##name( \
278  xorn_revision_t rev, xorn_selection_t sel, \
279  xorn_attst_t *state_return, outtype value_return); \
280  int ns##_set_##name( \
281  xorn_revision_t rev, xorn_selection_t sel, \
282  intype value); \
283  xorn_selection_t ns##_select_by_##name( \
284  xorn_revision_t rev, intype value);
285 
286 #define INT_ATTRIBUTE(ns, name) \
287  DECLARE_ATTRIBUTE_FUNCTIONS(ns, name, int, int *)
288 #define BOOL_ATTRIBUTE(ns, name) \
289  DECLARE_ATTRIBUTE_FUNCTIONS(ns, name, bool, bool *)
290 #define DOUBLE_ATTRIBUTE(ns, name) \
291  DECLARE_ATTRIBUTE_FUNCTIONS(ns, name, double, double *)
292 #define DOUBLE2D_ATTRIBUTE(ns, name) \
293  DECLARE_ATTRIBUTE_FUNCTIONS(ns, name, const struct xorn_double2d *, \
294  struct xorn_double2d *)
295 #define STRING_ATTRIBUTE(ns, name) \
296  DECLARE_ATTRIBUTE_FUNCTIONS(ns, name, const struct xorn_string *, \
297  struct xorn_string *)
298 #define LINE_ATTRIBUTE(ns, name) \
299  DECLARE_ATTRIBUTE_FUNCTIONS(ns, name, const struct xornsch_line_attr *,\
300  struct xornsch_line_attr *)
301 #define FILL_ATTRIBUTE(ns, name) \
302  DECLARE_ATTRIBUTE_FUNCTIONS(ns, name, const struct xornsch_fill_attr *,\
303  struct xornsch_fill_attr *)
304 
305  INT_ATTRIBUTE(xornsch, alignment)
306  INT_ATTRIBUTE(xornsch, angle)
307  INT_ATTRIBUTE(xornsch, color)
308  FILL_ATTRIBUTE(xornsch, fill)
309  INT_ATTRIBUTE(xornsch, fill_angle0)
310  INT_ATTRIBUTE(xornsch, fill_angle1)
311  DOUBLE_ATTRIBUTE(xornsch, fill_pitch0)
312  DOUBLE_ATTRIBUTE(xornsch, fill_pitch1)
313  INT_ATTRIBUTE(xornsch, fill_type)
314  DOUBLE_ATTRIBUTE(xornsch, fill_width)
315  BOOL_ATTRIBUTE(xornsch, is_bus)
316  BOOL_ATTRIBUTE(xornsch, is_inverted)
317  BOOL_ATTRIBUTE(xornsch, is_pin)
318  LINE_ATTRIBUTE(xornsch, line)
319  INT_ATTRIBUTE(xornsch, line_cap_style)
320  DOUBLE_ATTRIBUTE(xornsch, line_dash_length)
321  DOUBLE_ATTRIBUTE(xornsch, line_dash_space)
322  INT_ATTRIBUTE(xornsch, line_dash_style)
323  DOUBLE_ATTRIBUTE(xornsch, line_width)
324  BOOL_ATTRIBUTE(xornsch, mirror)
325  STRING_ATTRIBUTE(xornsch, pathdata)
326 DOUBLE2D_ATTRIBUTE(xornsch, pos)
327  DOUBLE_ATTRIBUTE(xornsch, pos_x)
328  DOUBLE_ATTRIBUTE(xornsch, pos_y)
329  DOUBLE_ATTRIBUTE(xornsch, radius)
330  BOOL_ATTRIBUTE(xornsch, selectable)
331  INT_ATTRIBUTE(xornsch, show_name_value)
332 DOUBLE2D_ATTRIBUTE(xornsch, size)
333  DOUBLE_ATTRIBUTE(xornsch, size_x)
334  DOUBLE_ATTRIBUTE(xornsch, size_y)
335  INT_ATTRIBUTE(xornsch, startangle)
336  INT_ATTRIBUTE(xornsch, sweepangle)
337  STRING_ATTRIBUTE(xornsch, text)
338  INT_ATTRIBUTE(xornsch, text_size)
339  BOOL_ATTRIBUTE(xornsch, visibility)
340 
341 #undef INT_ATTRIBUTE
342 #undef BOOL_ATTRIBUTE
343 #undef DOUBLE_ATTRIBUTE
344 #undef DOUBLE2D_ATTRIBUTE
345 #undef STRING_ATTRIBUTE
346 #undef LINE_ATTRIBUTE
347 #undef FILL_ATTRIBUTE
348 
349 #undef DECLARE_ATTRIBUTE_FUNCTIONS
350 
351 #ifdef __cplusplus
352 }
353 #endif
354 
355 #endif
int color
Color index.
Definition: xornstorage.h:189
Schematic arc.
Definition: xornstorage.h:177
struct xorn_double2d size
Coordinates of the second end minus coordinates of the first end in mils.
Definition: xornstorage.h:212
struct xorn_double2d size
Size in mils.
Definition: xornstorage.h:235
xorn_selection_t xorn_select_none()
Create an empty selection.
Definition: selection.cc:24
int xorn_get_objects(xorn_revision_t rev, xorn_object_t **objects_return, size_t *count_return)
Return a list of all objects in a revision.
Definition: object.cc:149
struct xornsch_line_attr line
Line style.
Definition: xornstorage.h:198
int xorn_relocate_object(xorn_revision_t rev, xorn_object_t ob, xorn_object_t attach_to, xorn_object_t insert_before)
Change the location of an object in the object structure of a transient revision. ...
Definition: manipulate.cc:219
int color
Color index.
Definition: xornstorage.h:213
void xorn_free_selection(xorn_selection_t sel)
Free the memory used for storing a selection.
Definition: selection.cc:277
struct xornsch_line_attr line
Line style.
Definition: xornstorage.h:229
Schematic picture.
Definition: xornstorage.h:233
struct xorn_revision * xorn_revision_t
Opaque type representing the contents of a file.
Definition: xornstorage.h:54
Schematic component.
Definition: xornstorage.h:202
void(* decref)(void *ptr)
A function which is called when a copy of the pointer is deleted.
Definition: xornstorage.h:157
struct xornsch_line_attr line
Line style.
Definition: xornstorage.h:183
double dash_space
Space between dashes in mils.
Definition: xornstorage.h:165
struct xorn_double2d size
Coordinate of second end minus coordinate of first end in mils.
Definition: xornstorage.h:219
Schematic net segment, bus segment, or pin.
Definition: xornstorage.h:217
int angle
Rotation angle in degrees.
Definition: xornstorage.h:236
Arbitrary reference-counted pointer.
Definition: xornstorage.h:154
struct xorn_string pathdata
Path data.
Definition: xornstorage.h:227
void xorn_finalize_revision(xorn_revision_t rev)
Prevent further changes to a revision.
Definition: revision.cc:91
bool xorn_object_is_selected(xorn_revision_t rev, xorn_selection_t sel, xorn_object_t ob)
Return whether an object exists in a revision and is selected in a selection.
Definition: selection.cc:266
struct xorn_double2d size
Size in mils.
Definition: xornstorage.h:188
struct xornsch_fill_attr fill
Fill style.
Definition: xornstorage.h:191
int angle
Angle of the text in degrees.
Definition: xornstorage.h:247
double dash_length
Dash length in mils.
Definition: xornstorage.h:164
int angle0
First angle of fill in degrees.
Definition: xornstorage.h:171
Schematic fill style.
Definition: xornstorage.h:168
const char * s
Pointer to the character data.
Definition: xornstorage.h:146
int xorn_get_object_location(xorn_revision_t rev, xorn_object_t ob, xorn_object_t *attached_to_return, unsigned int *position_return)
Get the location of an object in the object structure.
Definition: object.cc:93
double width
Width of fill lines in mils.
Definition: xornstorage.h:170
bool xorn_object_exists_in_revision(xorn_revision_t rev, xorn_object_t ob)
Return whether an object exists in a revision.
Definition: object.cc:25
int show_name_value
Attribute visibility control.
Definition: xornstorage.h:246
xorn_attst_t
Attribute status across multiple objects.
Definition: xornstorage.h:40
Schematic line style.
Definition: xornstorage.h:160
xorn_obtype_t xorn_get_object_type(xorn_revision_t rev, xorn_object_t ob)
Get the type of an object in a given revision.
Definition: object.cc:35
xorn_selection_t xorn_select_excluding(xorn_selection_t sel, xorn_object_t ob)
Create a selection which contains all the objects in an existing selection minus a given object...
Definition: selection.cc:156
void(* incref)(void *ptr)
A function which is called when the pointer is copied.
Definition: xornstorage.h:156
double x
X coordinate or offset.
Definition: xornstorage.h:151
double y
Y coordinate or offset.
Definition: xornstorage.h:151
int color
Color index.
Definition: xornstorage.h:182
struct xornsch_line_attr line
Line style.
Definition: xornstorage.h:190
double radius
Radius of the circle in mils.
Definition: xornstorage.h:196
int xorn_get_selected_objects(xorn_revision_t rev, xorn_selection_t sel, xorn_object_t **objects_return, size_t *count_return)
Return a list of objects which are in a revision as well as in a selection.
Definition: object.cc:215
struct xorn_selection * xorn_selection_t
Opaque type representing the identity of a set of objects.
Definition: xornstorage.h:56
bool selectable
Is the component selectable?
Definition: xornstorage.h:204
int xorn_get_added_objects(xorn_revision_t from_rev, xorn_revision_t to_rev, xorn_object_t **objects_return, size_t *count_return)
Return a list of objects which are in a revision but not in another.
Definition: object.cc:246
int sweepangle
Amount the arc sweeps in degrees.
Definition: xornstorage.h:181
Schematic text or attribute.
Definition: xornstorage.h:241
double pitch1
Second pitch/spacing of fill in mils.
Definition: xornstorage.h:174
bool mirror
Is the component mirrored around the Y axis?
Definition: xornstorage.h:206
double pitch0
First pitch/spacing of fill in mils.
Definition: xornstorage.h:172
struct xorn_double2d pos
Coordinates of the origin of the text item in mils.
Definition: xornstorage.h:242
void xorn_free_revision(xorn_revision_t rev)
Free the memory associated with a revision.
Definition: revision.cc:103
struct xorn_double2d pos
Center coordinates in mils.
Definition: xornstorage.h:195
int angle1
Second angle of fill in degrees.
Definition: xornstorage.h:173
struct xorn_double2d pos
Coordinate of first end in mils.
Definition: xornstorage.h:218
struct xorn_double2d pos
Coordinates of the lower left corner in mils.
Definition: xornstorage.h:234
int color
Color index.
Definition: xornstorage.h:197
double width
Line width in mils.
Definition: xornstorage.h:161
struct xorn_pointer pixmap
Reference to the pixmap data.
Definition: xornstorage.h:238
struct xorn_double2d pos
Origin coordinates in mils.
Definition: xornstorage.h:203
int xorn_get_objects_attached_to(xorn_revision_t rev, xorn_object_t ob, xorn_object_t **objects_return, size_t *count_return)
Return a list of objects in a revision which are attached to a certain object.
Definition: object.cc:176
int cap_style
Type of cap style.
Definition: xornstorage.h:162
void xorn_delete_selected_objects(xorn_revision_t rev, xorn_selection_t sel)
Delete some objects from a transient revision.
Definition: manipulate.cc:328
bool visibility
Visibility of the text.
Definition: xornstorage.h:245
double radius
Radius of the arc in mils.
Definition: xornstorage.h:179
int color
Color index.
Definition: xornstorage.h:220
xorn_selection_t xorn_copy_objects(xorn_revision_t dest, xorn_revision_t src, xorn_selection_t sel)
Copy some objects to a transient revision.
Definition: manipulate.cc:433
struct xorn_pointer symbol
Reference to the used symbol.
Definition: xornstorage.h:207
Schematic circle.
Definition: xornstorage.h:194
struct xorn_double2d pos
Coordinates of the first end in mils.
Definition: xornstorage.h:211
int xorn_get_removed_objects(xorn_revision_t from_rev, xorn_revision_t to_rev, xorn_object_t **objects_return, size_t *count_return)
Return a list of objects which are in a revision but not in another.
Definition: object.cc:277
xorn_selection_t xorn_select_object(xorn_object_t ob)
Create a selection containing a single object.
Definition: selection.cc:35
int text_size
Size of the text in points.
Definition: xornstorage.h:244
xorn_selection_t xorn_select_all_except(xorn_revision_t rev, xorn_selection_t sel)
Create a selection containing all objects in a revision except those in a given selection.
Definition: selection.cc:112
xorn_selection_t xorn_select_including(xorn_selection_t sel, xorn_object_t ob)
Create a selection which contains all the objects in an existing selection plus a given object...
Definition: selection.cc:136
int angle
Rotation angle of the component in degrees.
Definition: xornstorage.h:205
xorn_selection_t xorn_select_attached_to(xorn_revision_t rev, xorn_object_t ob)
Create a selection containing all objects in a revision attached to a given object.
Definition: selection.cc:61
xorn_selection_t xorn_select_intersection(xorn_selection_t sel0, xorn_selection_t sel1)
Create a selection containing the objects in both given selections.
Definition: selection.cc:201
xorn_object_t xorn_add_object(xorn_revision_t rev, xorn_obtype_t type, const void *data)
Add a new object to a transient revision.
Definition: manipulate.cc:60
Sequence of bytes.
Definition: xornstorage.h:145
int startangle
Starting angle of the arc in degrees.
Definition: xornstorage.h:180
bool xorn_selection_is_empty(xorn_revision_t rev, xorn_selection_t sel)
Return whether a selection is empty in a given revision.
Definition: selection.cc:246
bool mirror
Mirrored or normal picture.
Definition: xornstorage.h:237
bool is_inverted
Invert the pin when writing to a gEDA symbol file.
Definition: xornstorage.h:223
bool xorn_revision_is_transient(xorn_revision_t rev)
Return whether a revision can be changed.
Definition: revision.cc:76
size_t len
Length of the string in bytes.
Definition: xornstorage.h:147
struct xornsch_line_attr line
Line style.
Definition: xornstorage.h:214
bool is_bus
Does the object describe a bus or bus pin?
Definition: xornstorage.h:221
Schematic box.
Definition: xornstorage.h:186
void xorn_delete_object(xorn_revision_t rev, xorn_object_t ob)
Delete an object from a transient revision.
Definition: manipulate.cc:301
xorn_object_t xorn_copy_object(xorn_revision_t dest, xorn_revision_t src, xorn_object_t ob)
Copy an object to a transient revision.
Definition: manipulate.cc:392
xorn_selection_t xorn_select_all(xorn_revision_t rev)
Create a selection containing all objects in a revision.
Definition: selection.cc:90
const void * xorn_get_object_data(xorn_revision_t rev, xorn_object_t ob, xorn_obtype_t type)
Get a pointer to an object's data in a given revision.
Definition: object.cc:64
Pair of double values indicating a coordinate or offset.
Definition: xornstorage.h:150
void * ptr
The actual pointer.
Definition: xornstorage.h:155
struct xorn_double2d pos
Center coordinates in mils.
Definition: xornstorage.h:178
int alignment
Alignment (i.e., relative location of the origin) of the text.
Definition: xornstorage.h:248
int dash_style
Type of dash style.
Definition: xornstorage.h:163
int color
Color index.
Definition: xornstorage.h:228
struct xorn_object * xorn_object_t
Opaque type representing the identity of an object.
Definition: xornstorage.h:55
struct xorn_string text
The text strings.
Definition: xornstorage.h:249
struct xornsch_fill_attr fill
Fill style.
Definition: xornstorage.h:199
bool is_pin
Does the object describe a pin?
Definition: xornstorage.h:222
xorn_revision_t xorn_new_revision(xorn_revision_t rev)
Create a new revision, either from scratch or by copying an existing one.
Definition: revision.cc:56
struct xornsch_fill_attr fill
Fill style.
Definition: xornstorage.h:230
xorn_obtype_t
Object types, each corresponding to a data structure.
Definition: xornstorage.h:27
int xorn_set_object_data(xorn_revision_t rev, xorn_object_t ob, xorn_obtype_t type, const void *data)
Set an object in a transient revision to the given object type and data.
Definition: manipulate.cc:131
xorn_selection_t xorn_select_difference(xorn_selection_t sel0, xorn_selection_t sel1)
Create a selection containing the objects contained in one given selection, but not the other...
Definition: selection.cc:224
int type
Type of fill.
Definition: xornstorage.h:169
struct xorn_double2d pos
Lower left hand coordinates in mils.
Definition: xornstorage.h:187
Schematic path.
Definition: xornstorage.h:226
int xorn_get_modified_objects(xorn_revision_t from_rev, xorn_revision_t to_rev, xorn_object_t **objects_return, size_t *count_return)
Return a list of objects which exist in two revisions but have different type or data.
Definition: object.cc:307
int color
Color index.
Definition: xornstorage.h:243
Schematic line.
Definition: xornstorage.h:210
xorn_selection_t xorn_select_union(xorn_selection_t sel0, xorn_selection_t sel1)
Create a selection containing the objects in either given selection.
Definition: selection.cc:178