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/aadlprocessor.xpm"
24 /***********************************************
25  **                 AADL PROCESSOR            **
26  ***********************************************/
27 
28 #define AADL_PROCESSOR_DEPTH 0.5
29 
aadlprocessor_draw_borders(Aadlbox * aadlbox,DiaRenderer * renderer)30 static void aadlprocessor_draw_borders(Aadlbox *aadlbox, DiaRenderer *renderer)
31 {
32   DiaRendererClass *renderer_ops = DIA_RENDERER_GET_CLASS (renderer);
33   Element *elem;
34   real x, y, w, h;
35   Point points[4];
36 
37   assert(aadlbox != NULL);
38   assert(renderer != NULL);
39 
40   elem = &aadlbox->element;
41 
42   x = elem->corner.x;
43   y = elem->corner.y;
44   w = elem->width;
45   h = elem->height;
46 
47   renderer_ops->set_fillstyle(renderer, FILLSTYLE_SOLID);
48   renderer_ops->set_linewidth(renderer, AADLBOX_BORDERWIDTH);
49   renderer_ops->set_linestyle(renderer, LINESTYLE_SOLID);
50 
51   points[0].x = x;     points[0].y = y;
52   points[1].x = x + w; points[1].y = y + h;
53 
54   renderer_ops->fill_rect(renderer, points, points + 1, &aadlbox->fill_color);
55   renderer_ops->draw_rect(renderer, points, points + 1, &aadlbox->line_color);
56 
57   points[1].x = x + AADL_PROCESSOR_DEPTH;
58   points[1].y = y - AADL_PROCESSOR_DEPTH;
59 
60   points[2].x = x + w + AADL_PROCESSOR_DEPTH;
61   points[2].y = y - AADL_PROCESSOR_DEPTH;
62 
63   points[3].x = x + w, points[3].y = y;
64 
65   renderer_ops->fill_polygon(renderer, points, 4, &aadlbox->fill_color);
66   renderer_ops->draw_polygon(renderer, points, 4, &aadlbox->line_color);
67 
68   points[0].x = points[3].x, points[0].y = points[3].y;
69   points[1].x = points[0].x + AADL_PROCESSOR_DEPTH;
70   points[1].y = points[0].y - AADL_PROCESSOR_DEPTH;
71 
72   points[2].x = points[0].x + AADL_PROCESSOR_DEPTH;
73   points[2].y = points[0].y - AADL_PROCESSOR_DEPTH + h;
74 
75   points[3].x = points[0].x, points[3].y = points[0].y + h;
76 
77   renderer_ops->fill_polygon(renderer, points, 4, &aadlbox->fill_color);
78   renderer_ops->draw_polygon(renderer, points, 4, &aadlbox->line_color);
79 }
80 
81 static Aadlbox_specific aadlprocessor_specific =
82 {
83   (AadlProjectionFunc) aadldata_project_point_on_nearest_border,
84   (AadlTextPosFunc)    aadldata_text_position,
85   (AadlSizeFunc) aadldata_minsize
86 };
87 
88 
aadlprocessor_draw(Aadlbox * aadlbox,DiaRenderer * renderer)89 static void aadlprocessor_draw(Aadlbox *aadlbox, DiaRenderer *renderer)
90 {
91   aadlprocessor_draw_borders(aadlbox, renderer);
92   aadlbox_draw(aadlbox, renderer);
93 }
94 
95 ObjectTypeOps aadlprocessor_type_ops;
96 
97 DiaObjectType aadlprocessor_type =
98 {
99   "AADL - Processor",           /* name */
100   0,                      /* version */
101   (char **) aadlprocessor_xpm,  /* pixmap */
102 
103   &aadlprocessor_type_ops,       /* ops */
104   NULL,
105   &aadlprocessor_specific      /* user data */
106 };
107 
108 
109 static ObjectOps aadlprocessor_ops =
110 {
111   (DestroyFunc)         aadlbox_destroy,
112   (DrawFunc)            aadlprocessor_draw,              /* redefined */
113   (DistanceFunc)        aadlbox_distance_from,
114   (SelectFunc)          aadlbox_select,
115   (CopyFunc)            aadlbox_copy,
116   (MoveFunc)            aadlbox_move,
117   (MoveHandleFunc)      aadlbox_move_handle,
118   (GetPropertiesFunc)   object_create_props_dialog,
119   (ApplyPropertiesDialogFunc) object_apply_props_from_dialog,
120   (ObjectMenuFunc)      aadlbox_get_object_menu,
121   (DescribePropsFunc)   aadlbox_describe_props,
122   (GetPropsFunc)        aadlbox_get_props,
123   (SetPropsFunc)        aadlbox_set_props,
124   (TextEditFunc) 0,
125   (ApplyPropertiesListFunc) object_apply_props,
126 };
127 
128 
129 
aadlprocessor_create(Point * startpoint,void * user_data,Handle ** handle1,Handle ** handle2)130 static DiaObject *aadlprocessor_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2)
131 {
132   DiaObject *obj = aadlbox_create(startpoint, user_data, handle1, handle2);
133 
134   obj->type = &aadlprocessor_type;
135   obj->ops  = &aadlprocessor_ops;
136 
137   return obj;
138 }
139 
aadlprocessor_load(ObjectNode obj_node,int version,const char * filename)140 static DiaObject *aadlprocessor_load(ObjectNode obj_node, int version, const char *filename)
141 {
142   DiaObject *obj;
143   Point startpoint = {0.0,0.0};
144   Handle *handle1,*handle2;
145 
146   obj = aadlprocessor_create(&startpoint,&aadlprocessor_specific, &handle1,&handle2);
147   aadlbox_load(obj_node, version, filename, (Aadlbox *) obj);
148   return obj;
149 }
150 
151 
152 ObjectTypeOps aadlprocessor_type_ops =
153 {
154   (CreateFunc) aadlprocessor_create,
155   (LoadFunc)   aadlprocessor_load,/*using_properties*/     /* load */
156   (SaveFunc)   aadlbox_save,      /* save */
157   (GetDefaultsFunc)   NULL,
158   (ApplyDefaultsFunc) NULL
159 };
160