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.
23 #include "pixmaps/aadlbus.xpm"
25 /***********************************************
27 ***********************************************/
29 static void aadlbus_draw_borders(Aadlbox
*aadlbox
, DiaRenderer
*renderer
)
31 DiaRendererClass
*renderer_ops
= DIA_RENDERER_GET_CLASS (renderer
);
36 assert(aadlbox
!= NULL
);
37 assert(renderer
!= NULL
);
39 elem
= &aadlbox
->element
;
47 points
[0].y
= y
+ h
*0.5;
49 points
[1].x
= x
+ w
*AADL_BUS_ARROW_SIZE_FACTOR
;
52 points
[2].x
= x
+ w
*AADL_BUS_ARROW_SIZE_FACTOR
;
53 points
[2].y
= y
+ h
*AADL_BUS_HEIGHT_FACTOR
;
55 points
[3].x
= x
+ w
- w
*AADL_BUS_ARROW_SIZE_FACTOR
;
56 points
[3].y
= y
+ h
*AADL_BUS_HEIGHT_FACTOR
;
58 points
[4].x
= x
+ w
- w
*AADL_BUS_ARROW_SIZE_FACTOR
;
62 points
[5].y
= y
+ h
*0.5;
64 points
[6].x
= x
+ w
- w
*AADL_BUS_ARROW_SIZE_FACTOR
;
67 points
[7].x
= x
+ w
- w
*AADL_BUS_ARROW_SIZE_FACTOR
;
68 points
[7].y
= y
+ h
*(1-AADL_BUS_HEIGHT_FACTOR
);
70 points
[8].x
= x
+ w
*AADL_BUS_ARROW_SIZE_FACTOR
;
71 points
[8].y
= y
+ h
*(1-AADL_BUS_HEIGHT_FACTOR
);
73 points
[9].x
= x
+ w
*AADL_BUS_ARROW_SIZE_FACTOR
;
77 renderer_ops
->set_fillstyle(renderer
, FILLSTYLE_SOLID
);
78 renderer_ops
->set_linewidth(renderer
, AADLBOX_BORDERWIDTH
);
79 renderer_ops
->set_linestyle(renderer
, LINESTYLE_SOLID
);
81 renderer_ops
->fill_polygon(renderer
, points
, 10, &aadlbox
->fill_color
);
82 renderer_ops
->draw_polygon(renderer
, points
, 10, &aadlbox
->line_color
);
85 static void aadlbus_draw(Aadlbox
*aadlbox
, DiaRenderer
*renderer
)
87 aadlbus_draw_borders(aadlbox
, renderer
);
88 aadlbox_draw(aadlbox
, renderer
);
92 aadlbus_project_point_on_nearest_border(Aadlbox
*aadlbox
,Point
*p
,
95 Element
*element
= &aadlbox
->element
;
97 real w
= element
->width
;
98 real h
= element
->height
;
100 /* top left corner */
101 coord x1
= element
->corner
.x
;
102 coord y1
= element
->corner
.y
;
104 /* bottom right corner */
105 coord x2
= element
->corner
.x
+ w
;
106 coord y2
= element
->corner
.y
+ h
;
109 if ( p
->x
>= x1
+ w
*AADL_BUS_ARROW_SIZE_FACTOR
110 && p
->x
<= x2
- w
*AADL_BUS_ARROW_SIZE_FACTOR
)
114 rectangle
.left
= x1
+ w
*AADL_BUS_ARROW_SIZE_FACTOR
;
115 rectangle
.top
= y1
+ h
*AADL_BUS_HEIGHT_FACTOR
;
116 rectangle
.right
= x2
- w
*AADL_BUS_ARROW_SIZE_FACTOR
;
117 rectangle
.bottom
= y2
- h
*AADL_BUS_HEIGHT_FACTOR
;
119 aadlbox_project_point_on_rectangle(&rectangle
, p
, angle
);
127 if (p
->x
< x1
+ w
*AADL_BUS_ARROW_SIZE_FACTOR
) {
141 b
.x
= x1
+ w
*AADL_BUS_ARROW_SIZE_FACTOR
;
142 b
.y
= (p
->y
<y1
+0.5*h
)?y1
:y2
; /* up or down */
156 b
.x
= x2
- w
*AADL_BUS_ARROW_SIZE_FACTOR
;
157 b
.y
= (p
->y
<y1
+0.5*h
)?y1
:y2
; /* up or down */
165 /* intersection between (AB) and (MC) */
167 k1
= (b
.y
- a
.y
) / (b
.x
- a
.x
);
168 k2
= (m
.y
- c
.y
) / (m
.x
- c
.x
);
170 p
->x
= (m
.y
- a
.y
+ k1
*a
.x
- k2
*m
.x
) / (k1
- k2
);
171 p
->y
= a
.y
+ k1
* (p
->x
- a
.x
);
178 static Aadlbox_specific aadlbus_specific
=
180 (AadlProjectionFunc
) aadlbus_project_point_on_nearest_border
,
181 (AadlTextPosFunc
) aadlbus_text_position
,
182 (AadlSizeFunc
) aadlbus_minsize
185 extern ObjectTypeOps aadlbus_type_ops
;
187 DiaObjectType aadlbus_type
=
189 "AADL - Bus", /* name */
191 (char **) aadlbus_xpm
, /* pixmap */
193 &aadlbus_type_ops
, /* ops */
195 &aadlbus_specific
/* user data */
198 static ObjectOps aadlbus_ops
=
200 (DestroyFunc
) aadlbox_destroy
,
201 (DrawFunc
) aadlbus_draw
, /* redefined */
202 (DistanceFunc
) aadlbox_distance_from
,
203 (SelectFunc
) aadlbox_select
,
204 (CopyFunc
) aadlbox_copy
,
205 (MoveFunc
) aadlbox_move
,
206 (MoveHandleFunc
) aadlbox_move_handle
,
207 (GetPropertiesFunc
) object_create_props_dialog
,
208 (ApplyPropertiesFunc
) object_apply_props_from_dialog
,
209 (ObjectMenuFunc
) aadlbox_get_object_menu
,
210 (DescribePropsFunc
) aadlbox_describe_props
,
211 (GetPropsFunc
) aadlbox_get_props
,
212 (SetPropsFunc
) aadlbox_set_props
217 static DiaObject
*aadlbus_create(Point
*startpoint
, void *user_data
, Handle
**handle1
, Handle
**handle2
)
219 DiaObject
*obj
= aadlbox_create(startpoint
, user_data
, handle1
, handle2
);
221 obj
->type
= &aadlbus_type
;
222 obj
->ops
= &aadlbus_ops
;
227 static DiaObject
*aadlbus_load(ObjectNode obj_node
, int version
, const char *filename
)
230 Point startpoint
= {0.0,0.0};
231 Handle
*handle1
,*handle2
;
233 obj
= aadlbus_create(&startpoint
,&aadlbus_specific
, &handle1
,&handle2
);
234 aadlbox_load(obj_node
, version
, filename
, (Aadlbox
*) obj
);
239 ObjectTypeOps aadlbus_type_ops
=
241 (CreateFunc
) aadlbus_create
,
242 (LoadFunc
) aadlbus_load
,/*using_properties*/ /* load */
243 (SaveFunc
) aadlbox_save
, /* save */
244 (GetDefaultsFunc
) NULL
,
245 (ApplyDefaultsFunc
) NULL