2006-12-05 David Lodge <dave@cirt.net>
[dia.git] / objects / AADL / aadl.c
blob2b4f9d4c805ed8d4b7352148e0a1bcfe0a98d2a1
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 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
26 #include "object.h"
28 #include "intl.h"
29 #include "plug-ins.h"
31 #include "aadl.h"
33 extern DiaObjectType aadldata_type;
34 extern DiaObjectType aadlprocessor_type;
35 extern DiaObjectType aadldevice_type;
36 extern DiaObjectType aadlsystem_type;
37 extern DiaObjectType aadlsubprogram_type;
38 extern DiaObjectType aadlthreadgroup_type;
39 extern DiaObjectType aadlprocess_type;
40 extern DiaObjectType aadlthread_type;
41 extern DiaObjectType aadlbus_type;
42 extern DiaObjectType aadlmemory_type;
43 extern DiaObjectType aadlpackage_type;
46 DIA_PLUGIN_CHECK_INIT
48 PluginInitResult
49 dia_plugin_init(PluginInfo *info)
51 if (!dia_plugin_info_init(info, "AADL",
52 _("Architecture Analysis & Design Language diagram objects"),
53 NULL, NULL))
54 return DIA_PLUGIN_INIT_ERROR;
56 object_register_type(&aadldata_type);
57 object_register_type(&aadlprocessor_type);
58 object_register_type(&aadldevice_type);
59 object_register_type(&aadlsystem_type);
60 object_register_type(&aadlsubprogram_type);
61 object_register_type(&aadlthreadgroup_type);
62 object_register_type(&aadlprocess_type);
63 object_register_type(&aadlthread_type);
64 object_register_type(&aadlbus_type);
65 object_register_type(&aadlmemory_type);
66 object_register_type(&aadlpackage_type);
68 return DIA_PLUGIN_INIT_OK;
75 /***********************************************
76 ** MISC FUNCTIONS **
77 ***********************************************/
80 /* CENTER */
82 void aadlbox_center_text_position(Aadlbox *aadlbox, Point *p)
84 /* Center */
85 Element *elem = &aadlbox->element;
86 Point center;
87 real h, w;
89 text_calc_boundingbox(aadlbox->name, NULL);
90 h = aadlbox->name->height * aadlbox->name->numlines;
91 w = aadlbox->name->max_width;
93 center.x = elem->corner.x + 0.5*elem->width;
94 center.y = elem->corner.y + 0.5*elem->height;
96 p->x = center.x - 0.5*w;
97 p->y = center.y - 0.5*h + AADLBOX_TEXT_MARGIN; /* + aadlbox->name->ascent; */
101 /* MEMORY */
103 void aadlbox_memory_update_text_position(Aadlbox *aadlbox)
105 Element *elem = &aadlbox->element;
106 Point p1;
107 real h = 0;
109 text_calc_boundingbox(aadlbox->name, NULL);
110 h = elem->corner.y + AADLBOX_TEXT_MARGIN;
111 p1.x = elem->corner.x + AADLBOX_TEXT_MARGIN;
112 p1.y = h + aadlbox->name->ascent + 2*AADL_MEMORY_FACTOR*elem->height;
113 text_set_position(aadlbox->name, &p1);
117 /* INCLINED */
119 void aadlbox_inclined_update_text_position(Aadlbox *aadlbox)
121 Element *elem = &aadlbox->element;
122 Point p1;
123 real h = 0;
125 text_calc_boundingbox(aadlbox->name, NULL);
126 h = elem->corner.y + AADLBOX_TEXT_MARGIN;
127 p1.x = elem->corner.x + AADLBOX_TEXT_MARGIN
128 + AADLBOX_INCLINE_FACTOR*elem->width;
129 p1.y = h + aadlbox->name->ascent;
130 text_set_position(aadlbox->name, &p1);
133 void aadlbox_subprogram_update_text_position(Aadlbox *aadlbox)
135 Element *elem = &aadlbox->element;
136 DiaObject *obj = &elem->object;
137 Point p;
139 p.x = 0.5*(obj->handles[3]->pos.x + obj->handles[1]->pos.x) ;
140 p.y = 0.5*(obj->handles[3]->pos.y + obj->handles[1]->pos.y) + aadlbox->name->ascent;
141 text_set_position(aadlbox->name, &p);