1 /* gEDA - GPL Electronic Design Automation
2 * gschem - gEDA Schematic Capture
3 * Copyright (C) 1998-2007 Ales Hvezda
4 * Copyright (C) 1998-2007 gEDA Contributors (see ChangeLog for details)
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 USA
29 #ifdef HAVE_LIBDMALLOC
33 /*! \todo Finish function documentation!!!
35 * \par Function Description
39 * Adds an attribute <B>scm_attrib_name</B> with value <B>scm_attrib_value</B> to the given <B>object</B>.
40 The attribute has the visibility <B>scm_vis</B> and show <B>scm_show</B> flags.
41 The possible values are:
42 - <B>scm_vis</B>: scheme boolean. Visible (TRUE) or hidden (FALSE).
43 - <B>scm_show</B>: a list containing what to show: "name", "value", or both.
44 The return value is always TRUE.
46 SCM
g_add_attrib(SCM object
, SCM scm_attrib_name
,
47 SCM scm_attrib_value
, SCM scm_vis
, SCM scm_show
)
49 GSCHEM_TOPLEVEL
*w_current
=global_window_current
;
50 OBJECT
*o_current
=NULL
;
53 gchar
*attrib_name
=NULL
;
54 gchar
*attrib_value
=NULL
;
59 SCM_ASSERT (scm_is_string(scm_attrib_name
), scm_attrib_name
,
60 SCM_ARG2
, "add-attribute-to-object");
61 SCM_ASSERT (scm_is_string(scm_attrib_value
), scm_attrib_value
,
62 SCM_ARG3
, "add-attribute-to-object");
63 SCM_ASSERT (scm_boolean_p(scm_vis
), scm_vis
,
64 SCM_ARG4
, "add-attribute-to-object");
65 SCM_ASSERT (scm_list_p(scm_show
), scm_show
,
66 SCM_ARG5
, "add-attribute-to-object");
69 SCM_ASSERT(g_get_data_from_object_smob(object
, NULL
, &o_current
),
70 object
, SCM_ARG1
, "add-attribute-to-object");
75 attrib_name
= scm_to_locale_string(scm_attrib_name
);
76 attrib_value
= scm_to_locale_string(scm_attrib_value
);
77 scm_dynwind_free(attrib_name
);
78 scm_dynwind_free(attrib_value
);
79 vis
= SCM_NFALSEP(scm_vis
);
81 for (rest
= scm_show
; !scm_is_null(rest
); rest
= SCM_CDR(rest
)) {
82 /* Check every element in the list. It should be a string! */
83 SCM_ASSERT(scm_is_string(SCM_CAR(rest
)), SCM_CAR(rest
), SCM_ARG5
,
84 "add-attribute-to-object");
86 value
= scm_to_locale_string(SCM_CAR(rest
));
87 scm_dynwind_free(value
);
89 /* Only "name" or "value" strings are allowed */
90 SCM_ASSERT(!((strcasecmp(value
, "name") != 0) &&
91 (strcasecmp(value
, "value") != 0) ), SCM_CAR(rest
),
92 SCM_ARG5
, "add-attribute-to-object");
94 /* show = 1 => show value;
95 show = 2 => show name;
96 show = 3 => show both */
97 if (strcasecmp(value
, "value") == 0) {
100 else if (strcasecmp(value
, "name") == 0) {
104 /* Show name and value (show = 3) => show=0 for gschem */
109 newtext
= g_strdup_printf("%s=%s", attrib_name
, attrib_value
);
110 o_attrib_add_attrib (w_current
, newtext
, vis
, show
, o_current
);
117 /*! \todo Finish function documentation!!!
119 * \par Function Description
122 /*! \todo Finish function documentation!!!
124 * \par Function Description
128 * Sets several text properties of the given <B>attribute smob</B>:
129 - <B>coloridx</B>: The index of the text color, or -1 to keep previous color.
130 - <B>size</B>: Size (numeric) of the text, or -1 to keep the previous size.
131 - <B>alignment</B>: String with the alignment of the text. Possible values are:
132 * "" : Keep the previous alignment.
142 - <B>rotation</B>: Angle of the text, or -1 to keep previous angle.
143 - <B>x</B>, <B>y</B>: Coords of the text.
145 SCM
g_set_attrib_text_properties(SCM attrib_smob
, SCM scm_coloridx
,
146 SCM scm_size
, SCM scm_alignment
,
147 SCM scm_rotation
, SCM scm_x
, SCM scm_y
)
149 struct st_attrib_smob
*attribute
=
150 (struct st_attrib_smob
*) SCM_SMOB_DATA(attrib_smob
);
152 GSCHEM_TOPLEVEL
*w_current
= global_window_current
;
153 TOPLEVEL
*toplevel
= w_current
->toplevel
;
157 char *alignment_string
;
162 SCM_ASSERT (scm_is_integer(scm_coloridx
), scm_coloridx
,
163 SCM_ARG2
, "set-attribute-text-properties!");
164 SCM_ASSERT ( scm_is_integer(scm_size
),
165 scm_size
, SCM_ARG3
, "set-attribute-text-properties!");
166 SCM_ASSERT (scm_is_string(scm_alignment
), scm_alignment
,
167 SCM_ARG4
, "set-attribute-text-properties!");
168 SCM_ASSERT ( scm_is_integer(scm_rotation
),
169 scm_rotation
, SCM_ARG5
, "set-attribute-text-properties!");
170 SCM_ASSERT ( scm_is_integer(scm_x
),
171 scm_x
, SCM_ARG6
, "set-attribute-text-properties!");
172 SCM_ASSERT ( scm_is_integer(scm_y
),
173 scm_y
, SCM_ARG7
, "set-attribute-text-properties!");
175 color
= scm_to_int(scm_coloridx
);
177 SCM_ASSERT (!(color
< -1 || color
>= MAX_COLORS
),
178 scm_coloridx
, SCM_ARG2
, "set-attribute-text-properties!");
180 size
= scm_to_int(scm_size
);
181 rotation
= scm_to_int(scm_rotation
);
182 x
= scm_to_int(scm_x
);
183 y
= scm_to_int(scm_y
);
185 scm_dynwind_begin(0);
186 alignment_string
= scm_to_locale_string(scm_alignment
);
187 scm_dynwind_free(alignment_string
);
189 if (strlen(alignment_string
) == 0) {
192 if (strcmp(alignment_string
, "Lower Left") == 0) {
195 if (strcmp(alignment_string
, "Middle Left") == 0) {
198 if (strcmp(alignment_string
, "Upper Left") == 0) {
201 if (strcmp(alignment_string
, "Lower Middle") == 0) {
204 if (strcmp(alignment_string
, "Middle Middle") == 0) {
207 if (strcmp(alignment_string
, "Upper Middle") == 0) {
210 if (strcmp(alignment_string
, "Lower Right") == 0) {
213 if (strcmp(alignment_string
, "Middle Right") == 0) {
216 if (strcmp(alignment_string
, "Upper Right") == 0) {
219 if (alignment
== -2) {
221 SCM_ASSERT (scm_is_string(scm_alignment
), scm_alignment
,
222 SCM_ARG4
, "set-attribute-text-properties!");
227 attribute
->attribute
) {
228 object
= attribute
->attribute
;
231 o_erase_single(w_current
, object
);
239 object
->text
->size
= size
;
241 if (alignment
!= -1) {
242 object
->text
->alignment
= alignment
;
244 if (rotation
!= -1) {
245 object
->text
->angle
= rotation
;
247 o_text_recreate(object
);
248 if (!toplevel
->DONT_REDRAW
) {
249 o_text_draw(w_current
, object
);
256 /*! \brief Return a list of selected objects in a page.
257 * \par Function Description
258 * Returns a list containing the selected objects in the given page.
260 * \param [in] page_smob Page to look at.
262 * \return a list of objects in the selection list.
264 SCM
g_get_selected_objects(SCM page_smob
)
268 SCM return_list
= SCM_EOL
;
271 /* Get toplevel and the page */
272 SCM_ASSERT(g_get_data_from_page_smob(page_smob
, &toplevel
, &page
),
273 page_smob
, SCM_ARG1
, "get-selected-objects");
275 for (iter
= geda_list_get_glist(page
->selection_list
); iter
!= NULL
; iter
= iter
->next
) {
276 return_list
= scm_cons(g_make_object_smob(toplevel
, iter
->data
),
284 SCM
g_get_current_page(void)
286 return (g_make_page_smob(global_window_current
->toplevel
,
287 global_window_current
->toplevel
->page_current
));