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/aadlpackage.xpm"
24 
25 /* To have a really useful package element, we should make it a class of its
26    own, not inherited from aadlbox, with 2 special handles -- that could be
27    moved -- to draw the public/private separation */
28 
29 /***********************************************
30  **                 AADL PACKAGE              **
31  ***********************************************/
32 
33 
aadlpackage_draw_borders(Aadlbox * aadlbox,DiaRenderer * renderer)34 static void aadlpackage_draw_borders(Aadlbox *aadlbox, DiaRenderer *renderer)
35 {
36   DiaRendererClass *renderer_ops = DIA_RENDERER_GET_CLASS (renderer);
37   Element *elem;
38   real x, y, w, h;
39   Point points[9];
40 
41   assert(aadlbox != NULL);
42   assert(renderer != NULL);
43 
44   elem = &aadlbox->element;
45 
46   x = elem->corner.x;
47   y = elem->corner.y;
48   w = elem->width;
49   h = elem->height;
50 
51   renderer_ops->set_fillstyle(renderer, FILLSTYLE_SOLID);
52   renderer_ops->set_linewidth(renderer, AADLBOX_BORDERWIDTH);
53   renderer_ops->set_linestyle(renderer, LINESTYLE_SOLID);
54 
55   points[0].x = x;                 points[0].y = y;
56   points[1].x = x + 0.03 * w ;     points[1].y = y;
57   points[2].x = x + 0.08 * w ;     points[2].y = y -  AADL_PORT_MAX_OUT;
58   points[3].x = x + 0.40 * w ;     points[3].y = y -  AADL_PORT_MAX_OUT;
59   points[4].x = x + 0.45 * w ;     points[4].y = y;
60   points[5].x = x + w - 0.05 * w;  points[5].y = y;
61   points[6].x = x + w;             points[6].y = y + 0.05 * h;
62   points[7].x = x + w;             points[7].y = y + h;
63   points[8].x = x ;                points[8].y = y + h;
64 
65   renderer_ops->fill_polygon(renderer, points, 9, &aadlbox->fill_color);
66   renderer_ops->draw_polygon(renderer, points, 9, &aadlbox->line_color);
67 }
68 
69 
aadlpackage_draw(Aadlbox * aadlbox,DiaRenderer * renderer)70 static void aadlpackage_draw(Aadlbox *aadlbox, DiaRenderer *renderer)
71 {
72   aadlpackage_draw_borders(aadlbox, renderer);
73   aadlbox_draw(aadlbox, renderer);
74 }
75 
76 
77 static Aadlbox_specific aadlpackage_specific =
78 {
79   (AadlProjectionFunc) aadldata_project_point_on_nearest_border,
80   (AadlTextPosFunc)    aadldata_text_position,
81   (AadlSizeFunc) aadldata_minsize
82 };
83 
84 ObjectTypeOps aadlpackage_type_ops;
85 
86 DiaObjectType aadlpackage_type =
87 {
88   "AADL - Package",           /* name */
89   0,                      /* version */
90   (char **) aadlpackage_xpm,  /* pixmap */
91 
92   &aadlpackage_type_ops,       /* ops */
93   NULL,
94   &aadlpackage_specific      /* user data */
95 };
96 
97 
98 static ObjectOps aadlpackage_ops =
99 {
100   (DestroyFunc)         aadlbox_destroy,
101   (DrawFunc)            aadlpackage_draw,              /* redefined */
102   (DistanceFunc)        aadlbox_distance_from,
103   (SelectFunc)          aadlbox_select,
104   (CopyFunc)            aadlbox_copy,
105   (MoveFunc)            aadlbox_move,
106   (MoveHandleFunc)      aadlbox_move_handle,
107   (GetPropertiesFunc)   object_create_props_dialog,
108   (ApplyPropertiesDialogFunc) object_apply_props_from_dialog,
109   (ObjectMenuFunc)      aadlbox_get_object_menu,
110   (DescribePropsFunc)   aadlbox_describe_props,
111   (GetPropsFunc)        aadlbox_get_props,
112   (SetPropsFunc)        aadlbox_set_props,
113   (TextEditFunc) 0,
114   (ApplyPropertiesListFunc) object_apply_props,
115 };
116 
117 
118 
aadlpackage_create(Point * startpoint,void * user_data,Handle ** handle1,Handle ** handle2)119 static DiaObject *aadlpackage_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2)
120 {
121   DiaObject *obj = aadlbox_create(startpoint, user_data, handle1, handle2);
122 
123   obj->type = &aadlpackage_type;
124   obj->ops  = &aadlpackage_ops;
125 
126   return obj;
127 }
128 
aadlpackage_load(ObjectNode obj_node,int version,const char * filename)129 static DiaObject *aadlpackage_load(ObjectNode obj_node, int version, const char *filename)
130 {
131   DiaObject *obj;
132   Point startpoint = {0.0,0.0};
133   Handle *handle1,*handle2;
134 
135   obj = aadlpackage_create(&startpoint,&aadlpackage_specific, &handle1,&handle2);
136   aadlbox_load(obj_node, version, filename, (Aadlbox *) obj);
137 
138   return obj;
139 }
140 
141 
142 ObjectTypeOps aadlpackage_type_ops =
143 {
144   (CreateFunc) aadlpackage_create,
145   (LoadFunc)   aadlpackage_load,      /* load */
146   (SaveFunc)   aadlbox_save,          /* save */
147   (GetDefaultsFunc)   NULL,
148   (ApplyDefaultsFunc) NULL
149 };
150