1 /* AADL plugin for DIA
2 *
3 * Copyright (C) 2005 Laboratoire d'Informatique de Paris 6
4 * Author: Pierre Duquesne
5 *
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.
10 *
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.
15 *
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.
19 */
20
21
22 #include "aadl.h"
23 #include "pixmaps/aadlsubprogram.xpm"
24
25 /***********************************************
26 ** AADL SUBPROGRAM **
27 ***********************************************/
28
aadlsubprogram_draw_borders(Aadlbox * aadlbox,DiaRenderer * renderer)29 static void aadlsubprogram_draw_borders(Aadlbox *aadlbox, DiaRenderer *renderer)
30 {
31 DiaRendererClass *renderer_ops = DIA_RENDERER_GET_CLASS (renderer);
32 Element *elem;
33 real x, y, w, h;
34 Point center;
35
36 assert(aadlbox != NULL);
37 assert(renderer != NULL);
38
39 elem = &aadlbox->element;
40
41 x = elem->corner.x;
42 y = elem->corner.y;
43 w = elem->width;
44 h = elem->height;
45
46 center.x = x + 0.5*w;
47 center.y = y + 0.5*h;
48
49 renderer_ops->set_fillstyle(renderer, FILLSTYLE_SOLID);
50 renderer_ops->set_linewidth(renderer, AADLBOX_BORDERWIDTH);
51 renderer_ops->set_linestyle(renderer, LINESTYLE_SOLID);
52
53 renderer_ops->fill_ellipse(renderer, ¢er, w, h, &aadlbox->fill_color);
54 renderer_ops->draw_ellipse(renderer, ¢er, w, h, &aadlbox->line_color);
55
56 }
57
58 #define heavyside(n) (n>0?1:0)
59 #define sign(n) (n>=0?1:-1)
60 #define point_to_angle(p) (atan((p)->y/(p)->x) + M_PI*heavyside(-(p)->x)*sign((p)->y))
61
62 void
aadlsubprogram_project_point_on_nearest_border(Aadlbox * aadlbox,Point * p,real * angle)63 aadlsubprogram_project_point_on_nearest_border(Aadlbox *aadlbox,Point *p,
64 real *angle)
65 {
66 Point center;
67 real w, h, r, t, norm_factor;
68
69 w = aadlbox->element.width;
70 h = aadlbox->element.height;
71 center.x = aadlbox->element.corner.x + 0.5 * w;
72 center.y = aadlbox->element.corner.y + 0.5 * h;
73
74 point_sub(p, ¢er);
75
76 /* normalize ellipse to a circle */
77 r = w;
78 norm_factor = r/h;
79 p->y *= norm_factor;
80
81 t = point_to_angle(p);
82
83 p->x = 0.5*r*cos(t);
84 p->y = 0.5*r*sin(t);
85
86 /* unnormalize */
87 p->y /= norm_factor;
88
89 point_add(p, ¢er);
90 *angle = t;
91 }
92
93 static Aadlbox_specific aadlsubprogram_specific =
94 {
95 (AadlProjectionFunc) aadlsubprogram_project_point_on_nearest_border,
96 (AadlTextPosFunc) aadlsubprogram_text_position,
97 (AadlSizeFunc) aadlsubprogram_minsize
98 };
99
100
aadlsubprogram_draw(Aadlbox * aadlbox,DiaRenderer * renderer)101 static void aadlsubprogram_draw(Aadlbox *aadlbox, DiaRenderer *renderer)
102 {
103 aadlsubprogram_draw_borders(aadlbox, renderer);
104 aadlbox_draw(aadlbox, renderer);
105 }
106
107 ObjectTypeOps aadlsubprogram_type_ops;
108
109 DiaObjectType aadlsubprogram_type =
110 {
111 "AADL - Subprogram", /* name */
112 0, /* version */
113 (char **) aadlsubprogram_xpm, /* pixmap */
114
115 &aadlsubprogram_type_ops, /* ops */
116 NULL,
117 &aadlsubprogram_specific /* user data */
118 };
119
120
121 static ObjectOps aadlsubprogram_ops =
122 {
123 (DestroyFunc) aadlbox_destroy,
124 (DrawFunc) aadlsubprogram_draw, /* redefined */
125 (DistanceFunc) aadlbox_distance_from,
126 (SelectFunc) aadlbox_select,
127 (CopyFunc) aadlbox_copy,
128 (MoveFunc) aadlbox_move,
129 (MoveHandleFunc) aadlbox_move_handle,
130 (GetPropertiesFunc) object_create_props_dialog,
131 (ApplyPropertiesDialogFunc) object_apply_props_from_dialog,
132 (ObjectMenuFunc) aadlbox_get_object_menu,
133 (DescribePropsFunc) aadlbox_describe_props,
134 (GetPropsFunc) aadlbox_get_props,
135 (SetPropsFunc) aadlbox_set_props,
136 (TextEditFunc) 0,
137 (ApplyPropertiesListFunc) object_apply_props,
138 };
139
140
141
aadlsubprogram_create(Point * startpoint,void * user_data,Handle ** handle1,Handle ** handle2)142 static DiaObject *aadlsubprogram_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2)
143 {
144 DiaObject *obj = aadlbox_create(startpoint, user_data, handle1, handle2);
145
146 obj->type = &aadlsubprogram_type;
147 obj->ops = &aadlsubprogram_ops;
148
149 return obj;
150 }
151
aadlsubprogram_load(ObjectNode obj_node,int version,const char * filename)152 static DiaObject *aadlsubprogram_load(ObjectNode obj_node, int version, const char *filename)
153 {
154 DiaObject *obj;
155 Point startpoint = {0.0,0.0};
156 Handle *handle1,*handle2;
157
158 obj = aadlsubprogram_create(&startpoint,&aadlsubprogram_specific, &handle1,&handle2);
159 aadlbox_load(obj_node, version, filename, (Aadlbox *) obj);
160 return obj;
161 }
162
163
164 ObjectTypeOps aadlsubprogram_type_ops =
165 {
166 (CreateFunc) aadlsubprogram_create,
167 (LoadFunc) aadlsubprogram_load,/*using_properties*/ /* load */
168 (SaveFunc) aadlbox_save, /* save */
169 (GetDefaultsFunc) NULL,
170 (ApplyDefaultsFunc) NULL
171 };
172