1 /*
2  * item-data.h
3  *
4  *
5  * Author:
6  *  Richard Hult <rhult@hem.passagen.se>
7  *  Ricardo Markiewicz <rmarkie@fi.uba.ar>
8  *  Andres de Barbara <adebarbara@fi.uba.ar>
9  *  Marc Lorber <lorber.marc@wanadoo.fr>
10  *  Bernhard Schuster <bernhard@ahoi.io>
11  *
12  * Web page: https://ahoi.io/project/oregano
13  *
14  * Copyright (C) 1999-2001  Richard Hult
15  * Copyright (C) 2003,2004  Ricardo Markiewicz
16  * Copyright (C) 2009-2012  Marc Lorber
17  * Copyright (C) 2013       Bernhard Schuster
18  *
19  * This program is free software; you can redistribute it and/or
20  * modify it under the terms of the GNU General Public License as
21  * published by the Free Software Foundation; either version 2 of the
22  * License, or (at your option) any later version.
23  *
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
27  * General Public License for more details.
28  *
29  * You should have received a copy of the GNU General Public
30  * License along with this program; if not, write to the
31  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
32  * Boston, MA 02110-1301, USA.
33  */
34 #ifndef __ITEM_DATA_H
35 #define __ITEM_DATA_H
36 
37 // Base class for schematic model.
38 
39 #include <cairo/cairo.h>
40 
41 #include "coords.h"
42 #include "grid.h"
43 #include "schematic-print-context.h"
44 
45 #define TYPE_ITEM_DATA (item_data_get_type ())
46 #define ITEM_DATA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_ITEM_DATA, ItemData))
47 #define ITEM_DATA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_ITEM_DATA, ItemDataClass))
48 #define IS_ITEM_DATA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_ITEM_DATA))
49 #define IS_ITEM_DATA_CLASS(klass)                                                                  \
50 	(G_TYPE_CHECK_INSTANCE_GET_CLASS ((klass), TYPE_ITEM_DATA, ItemDataClass))
51 
52 typedef struct _ItemData ItemData;
53 typedef struct _ItemDataClass ItemDataClass;
54 typedef struct _ItemDataPriv ItemDataPriv;
55 
56 typedef enum {
57 	ID_FLIP_NONE = 0,
58 	ID_FLIP_HORIZ = 1 << 0,
59 	ID_FLIP_VERT = 1 << 1,
60 	ID_FLIP_MASK = 3
61 } IDFlip;
62 
63 struct _ItemData
64 {
65 	GObject parent;
66 	gulong moved_handler_id;
67 	gulong rotated_handler_id;
68 	gulong flipped_handler_id;
69 	gulong changed_handler_id;
70 	ItemDataPriv *priv;
71 };
72 
73 struct _ItemDataClass
74 {
75 	GObjectClass parent_class;
76 
77 	// Signals.
78 	void (*moved)(ItemData *data, Coords *delta);
79 
80 	// Methods.
81 	ItemData *(*clone)(ItemData *src);
82 	void (*copy)(ItemData *dest, ItemData *src);
83 	void (*rotate)(ItemData *data, int angle, Coords *center);
84 	void (*flip)(ItemData *data, IDFlip direction, Coords *center);
85 	void (*unreg)(ItemData *data);
86 	int (*reg)(ItemData *data);
87 	void (*changed)(ItemData *data);
88 
89 	char *(*get_refdes_prefix)(ItemData *data);
90 	void (*set_property)(ItemData *data, char *property, char *value);
91 	gboolean (*has_properties)(ItemData *data);
92 
93 	void (*print)(ItemData *data, cairo_t *cr, SchematicPrintContext *ctx);
94 };
95 
96 GType item_data_get_type (void);
97 // Create a new ItemData object
98 ItemData *item_data_new (void);
99 
100 // Clone an ItemData
101 //    param src A valid ItemData
102 ItemData *item_data_clone (ItemData *src);
103 
104 // Get Item position
105 void item_data_get_pos (ItemData *item_data, Coords *pos);
106 
107 // Set Item position
108 void item_data_set_pos (ItemData *item_data, Coords *pos);
109 
110 //  Move an ItemData
111 //  \param delta offset to move the item
112 void item_data_move (ItemData *item_data, const Coords *delta);
113 
114 // Get the bounding box of an item data
115 // Retrieve the bounding box of the item relative to position
116 //  \param p1 Where to store the upper-left point
117 //  \param p2 Where to store the lower-right point
118 void item_data_get_relative_bbox (ItemData *data, Coords *p1, Coords *p2);
119 
120 // Set the relative bounding box
121 void item_data_set_relative_bbox (ItemData *data, Coords *p1, Coords *p2);
122 // Get absolute bounding box
123 //  This function is like item_data_get_relative_bbox but it add
124 //  the item position to the bbox vertex
125 void item_data_get_absolute_bbox (ItemData *data, Coords *p1, Coords *p2);
126 
127 // Get the absolute bounding box of a list of items
128 //  This return a bbox that enclose all item in a list
129 void item_data_list_get_absolute_bbox (GList *item_data_list, Coords *p1, Coords *p2);
130 
131 // Rotate an item
132 void item_data_rotate (ItemData *data, int angle, Coords *center);
133 
134 // Flip an item
135 void item_data_flip (ItemData *data, IDFlip direction, Coords *center);
136 
137 // Get the Store associated for this item
138 //  Store is a class that hold all items in a schematic
139 gpointer item_data_get_store (ItemData *item_data);
140 
141 //  Unregister item in its Store
142 void item_data_unregister (ItemData *data);
143 
144 //  Register item in its Store
145 int item_data_register (ItemData *data);
146 
147 //  Get the prefix of a part reference
148 char *item_data_get_refdes_prefix (ItemData *data);
149 
150 gboolean item_data_has_properties (ItemData *date);
151 
152 //  Set property
153 void item_data_set_property (ItemData *data, char *property, char *value);
154 //  Print Item data
155 // This method implement the Cairo stuff for schematic print of an item.
156 void item_data_print (ItemData *data, cairo_t *cr, SchematicPrintContext *ctx);
157 
158 // Refresh the canvas representation of the item based on the itemdata's
159 // properties (or its subclasses)
160 void item_data_changed (ItemData *data);
161 
162 //
163 cairo_matrix_t *item_data_get_translate (ItemData *data);
164 cairo_matrix_t *item_data_get_rotate (ItemData *data);
165 
166 #endif
167