2006-12-05 David Lodge <dave@cirt.net>
[dia.git] / objects / AADL / aadlprocess.c
blobdfe851154b8addc36c75778b7a57151190f1539b
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/aadlprocess.xpm"
25 /***********************************************
26 ** AADL PROCESS **
27 ***********************************************/
30 void aadlbox_draw_inclined_box(Aadlbox *aadlbox, DiaRenderer *renderer,
31 LineStyle linestyle)
33 DiaRendererClass *renderer_ops = DIA_RENDERER_GET_CLASS (renderer);
34 Element *elem;
35 real x, y, w, h;
36 Point points[4];
38 assert(aadlbox != NULL);
39 assert(renderer != NULL);
41 elem = &aadlbox->element;
43 x = elem->corner.x;
44 y = elem->corner.y;
45 w = elem->width;
46 h = elem->height;
48 points[0].x = x + w * AADLBOX_INCLINE_FACTOR;
49 points[1].x = x + w;
50 points[0].y = points[1].y = y;
52 points[3].x = x;
53 points[2].x = x + w - w * AADLBOX_INCLINE_FACTOR;
54 points[3].y = points[2].y = y + h;
56 renderer_ops->set_fillstyle(renderer, FILLSTYLE_SOLID);
57 renderer_ops->set_linewidth(renderer, AADLBOX_BORDERWIDTH);
58 renderer_ops->set_linestyle(renderer, linestyle);
59 renderer_ops->set_dashlength(renderer, AADLBOX_DASH_LENGTH);
61 renderer_ops->fill_polygon(renderer, points, 4, &aadlbox->fill_color);
62 renderer_ops->draw_polygon(renderer, points, 4, &aadlbox->line_color);
66 static void aadlprocess_draw_borders(Aadlbox *aadlbox, DiaRenderer *renderer)
68 aadlbox_draw_inclined_box(aadlbox, renderer, LINESTYLE_SOLID);
72 void
73 aadlbox_inclined_project_point_on_nearest_border(Aadlbox *aadlbox,Point *p,
74 real *angle)
77 ++++++B------------+ +----------++++++++
78 + /000000000000/+ |0000000000| +
79 + /000000000000/ + |0000000000| +
80 + /000000000000/ + ----------> |0000000000| +
81 + /000000000000/ + |0000000000| +
82 +/000000000000/ + |0000000000| +
83 A------------ ++++++ +----------++++++++
84 */
86 Rectangle rectangle;
87 real w, h, delta_y, delta_x;
89 w = aadlbox->element.width;
90 h = aadlbox->element.height;
92 rectangle.top = aadlbox->element.corner.y;
93 rectangle.left = aadlbox->element.corner.x;
94 rectangle.bottom = aadlbox->element.corner.y + h;
95 rectangle.right = aadlbox->element.corner.x + w - w * AADLBOX_INCLINE_FACTOR;
97 delta_y = h - (p->y - aadlbox->element.corner.y);
98 delta_x = delta_y * (w * AADLBOX_INCLINE_FACTOR) / h;
100 p->x -= delta_x;
102 aadlbox_project_point_on_rectangle(&rectangle, p, angle);
104 delta_y = h - (p->y - aadlbox->element.corner.y);
105 delta_x = delta_y * (w * AADLBOX_INCLINE_FACTOR) / h;
107 p->x += delta_x;
110 static void aadlprocess_draw(Aadlbox *aadlbox, DiaRenderer *renderer)
112 aadlprocess_draw_borders(aadlbox, renderer);
113 aadlbox_draw(aadlbox, renderer);
117 static Aadlbox_specific aadlprocess_specific =
119 (AadlProjectionFunc) aadlbox_inclined_project_point_on_nearest_border,
120 (AadlTextPosFunc) aadlprocess_text_position,
121 (AadlSizeFunc) aadlprocess_minsize
125 ObjectTypeOps aadlprocess_type_ops;
127 DiaObjectType aadlprocess_type =
129 "AADL - Process", /* name */
130 0, /* version */
131 (char **) aadlprocess_xpm, /* pixmap */
133 &aadlprocess_type_ops, /* ops */
134 NULL,
135 &aadlprocess_specific /* user data */
139 static ObjectOps aadlprocess_ops =
141 (DestroyFunc) aadlbox_destroy,
142 (DrawFunc) aadlprocess_draw, /* redefined */
143 (DistanceFunc) aadlbox_distance_from,
144 (SelectFunc) aadlbox_select,
145 (CopyFunc) aadlbox_copy,
146 (MoveFunc) aadlbox_move,
147 (MoveHandleFunc) aadlbox_move_handle,
148 (GetPropertiesFunc) object_create_props_dialog,
149 (ApplyPropertiesFunc) object_apply_props_from_dialog,
150 (ObjectMenuFunc) aadlbox_get_object_menu,
151 (DescribePropsFunc) aadlbox_describe_props,
152 (GetPropsFunc) aadlbox_get_props,
153 (SetPropsFunc) aadlbox_set_props
158 static DiaObject *aadlprocess_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2)
160 DiaObject *obj = aadlbox_create(startpoint, user_data, handle1, handle2);
162 obj->type = &aadlprocess_type;
163 obj->ops = &aadlprocess_ops;
165 return obj;
168 static DiaObject *aadlprocess_load(ObjectNode obj_node, int version, const char *filename)
170 DiaObject *obj;
171 Point startpoint = {0.0,0.0};
172 Handle *handle1,*handle2;
174 obj = aadlprocess_create(&startpoint,&aadlprocess_specific, &handle1,&handle2);
175 aadlbox_load(obj_node, version, filename, (Aadlbox *) obj);
176 return obj;
180 ObjectTypeOps aadlprocess_type_ops =
182 (CreateFunc) aadlprocess_create,
183 (LoadFunc) aadlprocess_load,/*using_properties*/ /* load */
184 (SaveFunc) aadlbox_save, /* save */
185 (GetDefaultsFunc) NULL,
186 (ApplyDefaultsFunc) NULL