2006-12-05 David Lodge <dave@cirt.net>
[dia.git] / objects / AADL / aadldevice.c
blobff5b972a56123c5869bdf78a4da9ff133c2804c9
1 /* AADL plugin for DIA
3 * Copyright (C) 2005 Laboratoire d'Informatique de Paris 6
4 * Author: Pierre Duquesne
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #include "aadl.h"
23 #include "pixmaps/aadldevice.xpm"
24 /***********************************************
25 ** AADL DEVICE **
26 ***********************************************/
28 #define AADL_DEVICE_DEPTH 0.5
30 static void aadldevice_draw_borders(Aadlbox *aadlbox, DiaRenderer *renderer)
32 DiaRendererClass *renderer_ops = DIA_RENDERER_GET_CLASS (renderer);
33 Element *elem;
34 real x, y, w, h;
35 Point points[4];
37 assert(aadlbox != NULL);
38 assert(renderer != NULL);
40 elem = &aadlbox->element;
42 x = elem->corner.x;
43 y = elem->corner.y;
44 w = elem->width;
45 h = elem->height;
47 renderer_ops->set_fillstyle(renderer, FILLSTYLE_SOLID);
48 renderer_ops->set_linewidth(renderer, AADLBOX_BORDERWIDTH);
49 renderer_ops->set_linestyle(renderer, LINESTYLE_SOLID);
51 points[0].x = x; points[0].y = y;
52 points[1].x = x + w; points[1].y = y + h;
54 renderer_ops->fill_rect(renderer, points, points + 1, &aadlbox->fill_color);
55 renderer_ops->draw_rect(renderer, points, points + 1, &aadlbox->line_color);
57 points[1].x = x - AADL_DEVICE_DEPTH;
58 points[1].y = y - AADL_DEVICE_DEPTH;
60 points[2].x = x + w + AADL_DEVICE_DEPTH;
61 points[2].y = y - AADL_DEVICE_DEPTH;
63 points[3].x = x + w, points[3].y = y;
65 renderer_ops->fill_polygon(renderer, points, 4, &aadlbox->fill_color);
66 renderer_ops->draw_polygon(renderer, points, 4, &aadlbox->line_color);
68 points[0].x = points[3].x, points[0].y = points[3].y;
69 points[1].x = points[0].x + AADL_DEVICE_DEPTH;
70 points[1].y = points[0].y - AADL_DEVICE_DEPTH;
72 points[2].x = points[0].x + AADL_DEVICE_DEPTH;
73 points[2].y = points[0].y + AADL_DEVICE_DEPTH + h;
75 points[3].x = points[0].x, points[3].y = points[0].y + h;
77 renderer_ops->fill_polygon(renderer, points, 4, &aadlbox->fill_color);
78 renderer_ops->draw_polygon(renderer, points, 4, &aadlbox->line_color);
80 points[0].x = x + w;
81 points[0].y = y + h;
83 points[1].x = x + w + AADL_DEVICE_DEPTH;
84 points[1].y = y + h + AADL_DEVICE_DEPTH;
86 points[2].x = x - AADL_DEVICE_DEPTH;
87 points[2].y = y + h + AADL_DEVICE_DEPTH;
89 points[3].x = x;
90 points[3].y = y + h;
92 renderer_ops->fill_polygon(renderer, points, 4, &aadlbox->fill_color);
93 renderer_ops->draw_polygon(renderer, points, 4, &aadlbox->line_color);
95 points[0].x = x;
96 points[0].y = y;
98 points[1].x = x - AADL_DEVICE_DEPTH;
99 points[1].y = y - AADL_DEVICE_DEPTH;
101 renderer_ops->fill_polygon(renderer, points, 4, &aadlbox->fill_color);
102 renderer_ops->draw_polygon(renderer, points, 4, &aadlbox->line_color);
106 static Aadlbox_specific aadldevice_specific =
108 (AadlProjectionFunc) aadldata_project_point_on_nearest_border,
109 (AadlTextPosFunc) aadldata_text_position,
110 (AadlSizeFunc) aadldata_minsize
115 static void aadldevice_draw(Aadlbox *aadlbox, DiaRenderer *renderer)
117 aadldevice_draw_borders(aadlbox, renderer);
118 aadlbox_draw(aadlbox, renderer);
121 ObjectTypeOps aadldevice_type_ops;
123 DiaObjectType aadldevice_type =
125 "AADL - Device", /* name */
126 0, /* version */
127 (char **) aadldevice_xpm, /* pixmap */
129 &aadldevice_type_ops, /* ops */
130 NULL,
131 &aadldevice_specific /* user data */
135 static ObjectOps aadldevice_ops =
137 (DestroyFunc) aadlbox_destroy,
138 (DrawFunc) aadldevice_draw, /* redefined */
139 (DistanceFunc) aadlbox_distance_from,
140 (SelectFunc) aadlbox_select,
141 (CopyFunc) aadlbox_copy,
142 (MoveFunc) aadlbox_move,
143 (MoveHandleFunc) aadlbox_move_handle,
144 (GetPropertiesFunc) object_create_props_dialog,
145 (ApplyPropertiesFunc) object_apply_props_from_dialog,
146 (ObjectMenuFunc) aadlbox_get_object_menu,
147 (DescribePropsFunc) aadlbox_describe_props,
148 (GetPropsFunc) aadlbox_get_props,
149 (SetPropsFunc) aadlbox_set_props
154 static DiaObject *aadldevice_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2)
156 DiaObject *obj = aadlbox_create(startpoint, user_data, handle1, handle2);
158 obj->type = &aadldevice_type;
159 obj->ops = &aadldevice_ops;
161 return obj;
164 static DiaObject *aadldevice_load(ObjectNode obj_node, int version, const char *filename)
166 DiaObject *obj;
167 Point startpoint = {0.0,0.0};
168 Handle *handle1,*handle2;
170 obj = aadldevice_create(&startpoint,&aadldevice_specific, &handle1,&handle2);
171 aadlbox_load(obj_node, version, filename, (Aadlbox *) obj);
172 return obj;
176 ObjectTypeOps aadldevice_type_ops =
178 (CreateFunc) aadldevice_create,
179 (LoadFunc) aadldevice_load,/*using_properties*/ /* load */
180 (SaveFunc) aadlbox_save, /* save */
181 (GetDefaultsFunc) NULL,
182 (ApplyDefaultsFunc) NULL