1 /* Dia -- an diagram creation/manipulation program
2 * Copyright (C) 2006 Lars Clausen
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 /** This file contains functions for importers in particular to create
37 #include "properties.h"
38 #include "propinternals.h"
43 create_standard_text(real xpos
, real ypos
) {
44 DiaObjectType
*otype
= object_get_type("Standard - Text");
50 message_error(_("Can't find standard object"));
57 new_obj
= otype
->ops
->create(&point
, otype
->default_user_data
,
63 static PropDescription create_element_prop_descs
[] = {
64 { "elem_corner", PROP_TYPE_POINT
},
65 { "elem_width", PROP_TYPE_REAL
},
66 { "elem_height", PROP_TYPE_REAL
},
69 static GPtrArray
*make_element_props(real xpos
, real ypos
,
70 real width
, real height
)
76 props
= prop_list_from_descs(create_element_prop_descs
,pdtpp_true
);
77 g_assert(props
->len
== 3);
79 pprop
= g_ptr_array_index(props
,0);
80 pprop
->point_data
.x
= xpos
;
81 pprop
->point_data
.y
= ypos
;
82 rprop
= g_ptr_array_index(props
,1);
83 rprop
->real_data
= width
;
84 rprop
= g_ptr_array_index(props
,2);
85 rprop
->real_data
= height
;
91 create_standard_ellipse(real xpos
, real ypos
, real width
, real height
) {
92 DiaObjectType
*otype
= object_get_type("Standard - Ellipse");
100 message_error(_("Can't find standard object"));
107 new_obj
= otype
->ops
->create(&point
, otype
->default_user_data
,
110 props
= make_element_props(xpos
,ypos
,width
,height
);
111 new_obj
->ops
->set_props(new_obj
, props
);
112 prop_list_free(props
);
119 create_standard_box(real xpos
, real ypos
, real width
, real height
) {
120 DiaObjectType
*otype
= object_get_type("Standard - Box");
127 message_error(_("Can't find standard object"));
134 new_obj
= otype
->ops
->create(&point
, otype
->default_user_data
,
137 props
= make_element_props(xpos
,ypos
,width
,height
);
138 new_obj
->ops
->set_props(new_obj
, props
);
139 prop_list_free(props
);
144 static PropDescription create_line_prop_descs
[] = {
145 PROP_STD_START_ARROW
,
150 create_standard_polyline(int num_points
,
153 Arrow
*start_arrow
) {
154 DiaObjectType
*otype
= object_get_type("Standard - PolyLine");
157 MultipointCreateData
*pcd
;
161 message_error(_("Can't find standard object"));
165 pcd
= g_new(MultipointCreateData
, 1);
166 pcd
->num_points
= num_points
;
167 pcd
->points
= points
;
169 new_obj
= otype
->ops
->create(NULL
, pcd
,
174 props
= prop_list_from_descs(create_line_prop_descs
,pdtpp_true
);
175 g_assert(props
->len
== 2);
177 if (start_arrow
!= NULL
)
178 ((ArrowProperty
*)g_ptr_array_index(props
, 0))->arrow_data
= *start_arrow
;
179 if (end_arrow
!= NULL
)
180 ((ArrowProperty
*)g_ptr_array_index(props
, 1))->arrow_data
= *end_arrow
;
182 new_obj
->ops
->set_props(new_obj
, props
);
183 prop_list_free(props
);
189 create_standard_polygon(int num_points
,
191 DiaObjectType
*otype
= object_get_type("Standard - Polygon");
194 MultipointCreateData
*pcd
;
197 message_error(_("Can't find standard object"));
201 pcd
= g_new(MultipointCreateData
, 1);
202 pcd
->num_points
= num_points
;
203 pcd
->points
= points
;
205 new_obj
= otype
->ops
->create(NULL
, pcd
, &h1
, &h2
);
213 create_standard_bezierline(int num_points
,
216 Arrow
*start_arrow
) {
217 DiaObjectType
*otype
= object_get_type("Standard - BezierLine");
220 BezierCreateData
*bcd
;
224 message_error(_("Can't find standard object"));
228 bcd
= g_new(BezierCreateData
, 1);
229 bcd
->num_points
= num_points
;
230 bcd
->points
= points
;
232 new_obj
= otype
->ops
->create(NULL
, bcd
,
237 props
= prop_list_from_descs(create_line_prop_descs
,pdtpp_true
);
238 g_assert(props
->len
== 2);
240 if (start_arrow
!= NULL
)
241 ((ArrowProperty
*)g_ptr_array_index(props
, 0))->arrow_data
= *start_arrow
;
242 if (end_arrow
!= NULL
)
243 ((ArrowProperty
*)g_ptr_array_index(props
, 1))->arrow_data
= *end_arrow
;
245 new_obj
->ops
->set_props(new_obj
, props
);
246 prop_list_free(props
);
252 create_standard_beziergon(int num_points
,
254 DiaObjectType
*otype
= object_get_type("Standard - Beziergon");
257 BezierCreateData
*bcd
;
260 message_error(_("Can't find standard object"));
264 bcd
= g_new(BezierCreateData
, 1);
265 bcd
->num_points
= num_points
;
266 bcd
->points
= points
;
268 new_obj
= otype
->ops
->create(NULL
, bcd
,
277 static PropDescription create_arc_prop_descs
[] = {
278 { "curve_distance", PROP_TYPE_REAL
},
279 PROP_STD_START_ARROW
,
284 create_standard_arc(real x1
, real y1
, real x2
, real y2
,
287 Arrow
*start_arrow
) {
288 DiaObjectType
*otype
= object_get_type("Standard - Arc");
295 message_error(_("Can't find standard object"));
302 new_obj
= otype
->ops
->create(&point
, otype
->default_user_data
,
305 props
= prop_list_from_descs(create_arc_prop_descs
,pdtpp_true
);
306 g_assert(props
->len
== 3);
308 ((RealProperty
*)g_ptr_array_index(props
,0))->real_data
= radius
;
309 if (start_arrow
!= NULL
)
310 ((ArrowProperty
*)g_ptr_array_index(props
, 1))->arrow_data
= *start_arrow
;
311 if (end_arrow
!= NULL
)
312 ((ArrowProperty
*)g_ptr_array_index(props
, 2))->arrow_data
= *end_arrow
;
314 new_obj
->ops
->set_props(new_obj
, props
);
315 prop_list_free(props
);
320 static PropDescription create_file_prop_descs
[] = {
321 { "image_file", PROP_TYPE_FILE
},
325 create_standard_image(real xpos
, real ypos
, real width
, real height
,
327 DiaObjectType
*otype
= object_get_type("Standard - Image");
332 StringProperty
*sprop
;
335 message_error(_("Can't find standard object"));
342 new_obj
= otype
->ops
->create(&point
, otype
->default_user_data
,
345 props
= make_element_props(xpos
,ypos
,width
,height
);
346 new_obj
->ops
->set_props(new_obj
, props
);
347 prop_list_free(props
);
350 props
= prop_list_from_descs(create_file_prop_descs
,pdtpp_true
);
351 g_assert(props
->len
== 1);
352 sprop
= g_ptr_array_index(props
,0);
353 g_free(sprop
->string_data
);
354 sprop
->string_data
= g_strdup(file
);
355 new_obj
->ops
->set_props(new_obj
, props
);
356 prop_list_free(props
);
362 create_standard_group(GList
*items
) {
365 new_obj
= group_create((GList
*)items
);