2006-12-05 David Lodge <dave@cirt.net>
[dia.git] / objects / AADL / aadlmemory.c
blob01847d2ffae0427239660306c03ee7728b632ecd
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/aadlmemory.xpm"
24 /***********************************************
25 ** AADL MEMORY **
26 ***********************************************/
28 static void aadlmemory_draw_borders(Aadlbox *aadlbox, DiaRenderer *renderer)
30 DiaRendererClass *renderer_ops = DIA_RENDERER_GET_CLASS (renderer);
31 Element *elem;
32 real x, y, w, h;
33 BezPoint bez[5];
35 assert(aadlbox != NULL);
36 assert(renderer != NULL);
38 elem = &aadlbox->element;
40 x = elem->corner.x;
41 y = elem->corner.y;
42 w = elem->width;
43 h = elem->height;
45 bez[0].type = BEZ_MOVE_TO;
46 bez[1].type = BEZ_CURVE_TO;
47 bez[2].type = BEZ_LINE_TO;
48 bez[3].type = BEZ_CURVE_TO;
49 bez[4].type = BEZ_LINE_TO;
51 bez[0].p1.x = x;
52 bez[0].p1.y = y + h*AADL_MEMORY_FACTOR;
54 bez[1].p1.x = x;
55 bez[1].p1.y = y;
56 bez[1].p2.x = x+w;
57 bez[1].p2.y = y;
58 bez[1].p3.x = x + w;
59 bez[1].p3.y = y + h*AADL_MEMORY_FACTOR;
61 bez[2].p1.x = x + w;
62 bez[2].p1.y = y + h - h*AADL_MEMORY_FACTOR;
64 bez[3].p1.x = x + w;
65 bez[3].p1.y = y + h;
66 bez[3].p2.x = x;
67 bez[3].p2.y = y + h;
68 bez[3].p3.x = x;
69 bez[3].p3.y = y + h - h*AADL_MEMORY_FACTOR;
71 point_copy(&bez[4].p1, &bez[0].p1);
73 renderer_ops->set_fillstyle(renderer, FILLSTYLE_SOLID);
74 renderer_ops->set_linewidth(renderer, AADLBOX_BORDERWIDTH);
75 renderer_ops->set_linestyle(renderer, LINESTYLE_SOLID);
77 renderer_ops->fill_bezier(renderer, bez, 5, &aadlbox->fill_color);
78 renderer_ops->draw_bezier(renderer, bez, 5, &aadlbox->line_color);
80 bez[1].p1.x = x;
81 bez[1].p1.y = y + 2*h*AADL_MEMORY_FACTOR;
82 bez[1].p2.x = x+w;
83 bez[1].p2.y = y+ 2*h*AADL_MEMORY_FACTOR;
84 bez[1].p3.x = x + w;
85 bez[1].p3.y = y + h*AADL_MEMORY_FACTOR;
87 renderer_ops->draw_bezier(renderer, bez, 3, &aadlbox->line_color);
91 static Aadlbox_specific aadlmemory_specific =
93 (AadlProjectionFunc) aadldata_project_point_on_nearest_border,
94 (AadlTextPosFunc) aadlmemory_text_position,
95 (AadlSizeFunc) aadlmemory_minsize
100 static void aadlmemory_draw(Aadlbox *aadlbox, DiaRenderer *renderer)
102 aadlmemory_draw_borders(aadlbox, renderer);
103 aadlbox_draw(aadlbox, renderer);
106 ObjectTypeOps aadlmemory_type_ops;
108 DiaObjectType aadlmemory_type =
110 "AADL - Memory", /* name */
111 0, /* version */
112 (char **) aadlmemory_xpm, /* pixmap */
114 &aadlmemory_type_ops, /* ops */
115 NULL,
116 &aadlmemory_specific /* user data */
120 static ObjectOps aadlmemory_ops =
122 (DestroyFunc) aadlbox_destroy,
123 (DrawFunc) aadlmemory_draw, /* redefined */
124 (DistanceFunc) aadlbox_distance_from,
125 (SelectFunc) aadlbox_select,
126 (CopyFunc) aadlbox_copy,
127 (MoveFunc) aadlbox_move,
128 (MoveHandleFunc) aadlbox_move_handle,
129 (GetPropertiesFunc) object_create_props_dialog,
130 (ApplyPropertiesFunc) object_apply_props_from_dialog,
131 (ObjectMenuFunc) aadlbox_get_object_menu,
132 (DescribePropsFunc) aadlbox_describe_props,
133 (GetPropsFunc) aadlbox_get_props,
134 (SetPropsFunc) aadlbox_set_props
139 static DiaObject *aadlmemory_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2)
141 DiaObject *obj = aadlbox_create(startpoint, user_data, handle1, handle2);
143 obj->type = &aadlmemory_type;
144 obj->ops = &aadlmemory_ops;
146 return obj;
149 static DiaObject *aadlmemory_load(ObjectNode obj_node, int version, const char *filename)
151 DiaObject *obj;
152 Point startpoint = {0.0,0.0};
153 Handle *handle1,*handle2;
155 obj = aadlmemory_create(&startpoint,&aadlmemory_specific, &handle1,&handle2);
156 aadlbox_load(obj_node, version, filename, (Aadlbox *) obj);
157 return obj;
161 ObjectTypeOps aadlmemory_type_ops =
163 (CreateFunc) aadlmemory_create,
164 (LoadFunc) aadlmemory_load,/*using_properties*/ /* load */
165 (SaveFunc) aadlbox_save, /* save */
166 (GetDefaultsFunc) NULL,
167 (ApplyDefaultsFunc) NULL