1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007-2019 Nicola Fontana <ntd at entidi.it>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library 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 GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
22 * SECTION:adg-title-block
23 * @short_description: A title block entity
25 * Title blocks are commonly used in technical drawings to include
26 * additional information not strictly related to physical dimensions,
27 * such as title, material of the represented part, special treatments,
30 * Actually this entity is only a place-holder: it will be implemented
31 * properly in a 0.6.x release, after having AdgToyTable in place.
39 * All fields are privates and should not be used directly.
40 * Use its public methods instead.
46 #include "adg-internal.h"
48 #include "adg-table.h"
49 #include "adg-table-row.h"
50 #include "adg-table-cell.h"
52 #include "adg-title-block.h"
53 #include "adg-title-block-private.h"
56 #define _ADG_OLD_OBJECT_CLASS ((GObjectClass *) adg_title_block_parent_class)
59 G_DEFINE_TYPE_WITH_PRIVATE(AdgTitleBlock
, adg_title_block
, ADG_TYPE_TABLE
);
74 static void _adg_finalize (GObject
*object
);
75 static void _adg_get_property (GObject
*object
,
79 static void _adg_set_property (GObject
*object
,
86 adg_title_block_class_init(AdgTitleBlockClass
*klass
)
88 GObjectClass
*gobject_class
;
91 gobject_class
= (GObjectClass
*) klass
;
93 gobject_class
->finalize
= _adg_finalize
;
94 gobject_class
->set_property
= _adg_set_property
;
95 gobject_class
->get_property
= _adg_get_property
;
97 param
= g_param_spec_string("title",
99 P_("A descriptive title of the drawing"),
102 g_object_class_install_property(gobject_class
, PROP_TITLE
, param
);
104 param
= g_param_spec_string("drawing",
106 P_("The name of the drawing: the ADG canvas does not make any assumtpion on this text string"),
109 g_object_class_install_property(gobject_class
, PROP_DRAWING
, param
);
111 param
= g_param_spec_string("size",
113 P_("The media size to be used to print the drawing, usually something like \"A3\" or \"Letter\""),
116 g_object_class_install_property(gobject_class
, PROP_SIZE
, param
);
118 param
= g_param_spec_string("scale",
120 P_("The scale of the drawing, if it makes sense"),
123 g_object_class_install_property(gobject_class
, PROP_SCALE
, param
);
125 param
= g_param_spec_string("author",
127 P_("Name and last name of the author of the drawing"),
130 g_object_class_install_property(gobject_class
, PROP_AUTHOR
, param
);
132 param
= g_param_spec_string("date",
134 P_("The date this drawing has been generated: setting it to an empty string will fallback to today in the preferred representation for the current locale"),
137 g_object_class_install_property(gobject_class
, PROP_DATE
, param
);
139 param
= g_param_spec_object("logo",
141 P_("An entity to be displayed in the title block as the logo of the owner: the containing cell has a 1:1 ratio"),
144 g_object_class_install_property(gobject_class
, PROP_LOGO
, param
);
146 param
= g_param_spec_object("projection",
147 P_("Projection Scheme"),
148 P_("The entity usually reserved to identify the projection scheme adopted by this drawing"),
151 g_object_class_install_property(gobject_class
, PROP_PROJECTION
, param
);
155 adg_title_block_init(AdgTitleBlock
*title_block
)
157 AdgTable
*table
= (AdgTable
*) title_block
;
158 AdgTitleBlockPrivate
*data
= adg_title_block_get_instance_private(title_block
);
163 data
->drawing
= NULL
;
168 data
->projection
= NULL
;
170 /* By default the title block should be floating */
171 adg_entity_switch_floating((AdgEntity
*) title_block
, TRUE
);
173 /* Create the title block template*/
176 row
= adg_table_row_new(table
);
177 adg_table_cell_new_with_width(row
, 62);
178 adg_table_cell_new_full(row
, 200, "title", _("TITLE"), TRUE
);
181 row
= adg_table_row_new(table
);
182 adg_table_cell_new_full(row
, 62, "logo", NULL
, FALSE
);
183 adg_table_cell_new_full(row
, 40, "size", _("SIZE"), TRUE
);
184 adg_table_cell_new_full(row
, 60, "scale", _("SCALE"), TRUE
);
185 adg_table_cell_new_full(row
, 100, "drawing", _("DRAWING"), TRUE
);
188 row
= adg_table_row_new(table
);
189 adg_table_cell_new_full(row
, 62, "projection", NULL
, TRUE
);
190 adg_table_cell_new_full(row
, 100, "author", _("AUTHOR"), TRUE
);
191 adg_table_cell_new_full(row
, 100, "date", _("DATE"), TRUE
);
195 _adg_finalize(GObject
*object
)
197 AdgTitleBlockPrivate
*data
= adg_title_block_get_instance_private((AdgTitleBlock
*) object
);
200 g_free(data
->drawing
);
203 g_free(data
->author
);
206 if (_ADG_OLD_OBJECT_CLASS
->finalize
)
207 _ADG_OLD_OBJECT_CLASS
->finalize(object
);
211 _adg_get_property(GObject
*object
, guint prop_id
,
212 GValue
*value
, GParamSpec
*pspec
)
214 AdgTitleBlockPrivate
*data
= adg_title_block_get_instance_private((AdgTitleBlock
*) object
);
218 g_value_set_string(value
, data
->title
);
221 g_value_set_string(value
, data
->drawing
);
224 g_value_set_string(value
, data
->size
);
227 g_value_set_string(value
, data
->scale
);
230 g_value_set_string(value
, data
->author
);
233 g_value_set_string(value
, data
->date
);
236 g_value_set_object(value
, data
->logo
);
238 case PROP_PROJECTION
:
239 g_value_set_object(value
, data
->projection
);
242 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
248 _adg_set_property(GObject
*object
, guint prop_id
,
249 const GValue
*value
, GParamSpec
*pspec
)
251 AdgTitleBlockPrivate
*data
= adg_title_block_get_instance_private((AdgTitleBlock
*) object
);
252 AdgTable
*table
= (AdgTable
*) object
;
258 data
->title
= g_value_dup_string(value
);
259 cell
= adg_table_get_cell(table
, "title");
260 adg_table_cell_set_text_value(cell
, data
->title
);
263 g_free(data
->drawing
);
264 data
->drawing
= g_value_dup_string(value
);
265 cell
= adg_table_get_cell(table
, "drawing");
266 adg_table_cell_set_text_value(cell
, data
->drawing
);
270 data
->size
= g_value_dup_string(value
);
271 cell
= adg_table_get_cell(table
, "size");
272 adg_table_cell_set_text_value(cell
, data
->size
);
276 data
->scale
= g_value_dup_string(value
);
277 cell
= adg_table_get_cell(table
, "scale");
278 adg_table_cell_set_text_value(cell
, data
->scale
);
281 g_free(data
->author
);
282 data
->author
= g_value_dup_string(value
);
283 cell
= adg_table_get_cell(table
, "author");
284 adg_table_cell_set_text_value(cell
, data
->author
);
288 if (g_value_get_string(value
) == NULL
) {
289 /* NULL means the date must be automatically updated */
291 char buffer
[100] = { 0 };
293 gdate
= g_date_new();
294 g_date_set_time_t(gdate
, time (NULL
));
295 g_date_strftime(buffer
, sizeof(buffer
), "%x", gdate
);
298 data
->date
= g_strdup(buffer
);
300 data
->date
= g_value_dup_string(value
);
302 cell
= adg_table_get_cell(table
, "date");
303 adg_table_cell_set_text_value(cell
, data
->date
);
306 data
->logo
= g_value_get_object(value
);
307 cell
= adg_table_get_cell(table
, "logo");
308 adg_table_cell_set_value(cell
, data
->logo
);
309 adg_table_cell_set_value_pos_explicit(cell
, 0.5, 1, 0.5, 0.5);
311 case PROP_PROJECTION
:
312 data
->projection
= g_value_get_object(value
);
313 cell
= adg_table_get_cell(table
, "projection");
314 adg_table_cell_set_value(cell
, data
->projection
);
315 adg_table_cell_set_value_pos_explicit(cell
, 0.5, 0.5, 0.5, 0.5);
318 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
325 * adg_title_block_new:
327 * Creates a new empty title block entity.
329 * Returns: (transfer full): the newly created title block entity.
334 adg_title_block_new(void)
336 return g_object_new(ADG_TYPE_TITLE_BLOCK
, NULL
);
340 * adg_title_block_set_title:
341 * @title_block: an #AdgTitleBlock entity
342 * @title: the new title
344 * Sets a new title on the title block.
349 adg_title_block_set_title(AdgTitleBlock
*title_block
, const gchar
*title
)
351 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block
));
352 g_object_set(title_block
, "title", title
, NULL
);
356 * adg_title_block_get_title:
357 * @title_block: an #AdgTitleBlock entity
359 * Gets the descriptive title associated to this title block.
360 * The returned string is owned by @title_block and should not
361 * be modifed or freed.
363 * Returns: (transfer none): the title or <constant>NULL</constant> on no title or errors.
368 adg_title_block_get_title(AdgTitleBlock
*title_block
)
370 AdgTitleBlockPrivate
*data
;
372 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block
), NULL
);
374 data
= adg_title_block_get_instance_private(title_block
);
379 * adg_title_block_set_drawing:
380 * @title_block: an #AdgTitleBlock entity
381 * @drawing: the new drawing name
383 * Sets a new drawing name on the title block.
388 adg_title_block_set_drawing(AdgTitleBlock
*title_block
, const gchar
*drawing
)
390 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block
));
391 g_object_set(title_block
, "drawing", drawing
, NULL
);
395 * adg_title_block_get_drawing:
396 * @title_block: an #AdgTitleBlock entity
398 * Gets the drawing name, commonly used to specify the file name.
399 * The returned string is owned by @title_block and should not
400 * be modifed or freed.
402 * Returns: (transfer none): the drawing name or <constant>NULL</constant> on no name or errors.
407 adg_title_block_get_drawing(AdgTitleBlock
*title_block
)
409 AdgTitleBlockPrivate
*data
;
411 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block
), NULL
);
413 data
= adg_title_block_get_instance_private(title_block
);
414 return data
->drawing
;
418 * adg_title_block_set_size:
419 * @title_block: an #AdgTitleBlock entity
420 * @size: the new size
422 * Sets a new size on the title block.
427 adg_title_block_set_size(AdgTitleBlock
*title_block
, const gchar
*size
)
429 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block
));
430 g_object_set(title_block
, "size", size
, NULL
);
434 * adg_title_block_get_size:
435 * @title_block: an #AdgTitleBlock entity
437 * Gets the media size (a descriptive name) where this drawing will
438 * be printed. Usually contains something like <constant>"A4"</constant>
439 * or <constant>"Letter"</constant>.
440 * The returned string is owned by @title_block and should not
441 * be modifed or freed.
443 * Returns: (transfer none): the size or <constant>NULL</constant> on no size or errors.
448 adg_title_block_get_size(AdgTitleBlock
*title_block
)
450 AdgTitleBlockPrivate
*data
;
452 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block
), NULL
);
454 data
= adg_title_block_get_instance_private(title_block
);
459 * adg_title_block_set_scale:
460 * @title_block: an #AdgTitleBlock entity
461 * @scale: the new scale
463 * Sets a new scale on the title block.
468 adg_title_block_set_scale(AdgTitleBlock
*title_block
, const gchar
*scale
)
470 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block
));
471 g_object_set(title_block
, "scale", scale
, NULL
);
475 * adg_title_block_get_scale:
476 * @title_block: an #AdgTitleBlock entity
478 * Gets the scale descriptive name of the drawing.
480 * Returns: (transfer none): the scale text or <constant>NULL</constant> on no scale or errors.
485 adg_title_block_get_scale(AdgTitleBlock
*title_block
)
487 AdgTitleBlockPrivate
*data
;
489 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block
), NULL
);
491 data
= adg_title_block_get_instance_private(title_block
);
496 * adg_title_block_set_author:
497 * @title_block: an #AdgTitleBlock entity
498 * @author: the new author
500 * Sets a new author on the title block.
505 adg_title_block_set_author(AdgTitleBlock
*title_block
, const gchar
*author
)
507 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block
));
508 g_object_set(title_block
, "author", author
, NULL
);
512 * adg_title_block_get_author:
513 * @title_block: an #AdgTitleBlock entity
515 * Gets the author's name of the drawing.
517 * Returns: (transfer none): the author or <constant>NULL</constant> on no author or errors.
522 adg_title_block_get_author(AdgTitleBlock
*title_block
)
524 AdgTitleBlockPrivate
*data
;
526 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block
), NULL
);
528 data
= adg_title_block_get_instance_private(title_block
);
533 * adg_title_block_set_date:
534 * @title_block: an #AdgTitleBlock entity
535 * @date: the new date
537 * Sets a new date on the title block. By default the date is
538 * set to <constant>NULL</constant> and it will be implicitely
539 * rendered using the*preferred representation for the current
540 * local of the actual date. This is roughly equivalent to:
542 * <informalexample><programlisting language="C">
543 * strftime(buffer, sizeof(buffer), "%x", now);
544 * adg_title_block_set_date(title_block, buffer);
545 * </programlisting></informalexample>
547 * To not render any value, use an empty string as @date.
552 adg_title_block_set_date(AdgTitleBlock
*title_block
, const gchar
*date
)
554 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block
));
555 g_object_set(title_block
, "date", date
, NULL
);
559 * adg_title_block_get_date:
560 * @title_block: an #AdgTitleBlock entity
562 * Gets the date of the rendering set on @title_block.
564 * Returns: (transfer none): the date or <constant>NULL</constant> on no date or errors.
569 adg_title_block_get_date(AdgTitleBlock
*title_block
)
571 AdgTitleBlockPrivate
*data
;
573 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block
), NULL
);
575 data
= adg_title_block_get_instance_private(title_block
);
580 * adg_title_block_set_logo:
581 * @title_block: an #AdgTitleBlock entity
582 * @logo: the new logo
584 * Sets a new logo on the title block. This function will add
585 * a reference to @logo, removing the eventual reference held
586 * to the old logo, hence possibly destroying the old endity.
588 * The space reserved for the logo is 56x56, so try to keep the
589 * new logo near this size or scale it accordingly.
594 adg_title_block_set_logo(AdgTitleBlock
*title_block
, AdgEntity
*logo
)
596 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block
));
597 g_object_set(title_block
, "logo", logo
, NULL
);
601 * adg_title_block_logo:
602 * @title_block: an #AdgTitleBlock entity
604 * Gets the logo bound to this title block.
605 * The returned object is owned by @title_block and should not
606 * be unreferenced although can be freely modified.
608 * Returns: (transfer none): the logo or <constant>NULL</constant> on no logo or errors.
613 adg_title_block_logo(AdgTitleBlock
*title_block
)
615 AdgTitleBlockPrivate
*data
;
617 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block
), NULL
);
619 data
= adg_title_block_get_instance_private(title_block
);
624 * adg_title_block_set_projection:
625 * @title_block: an #AdgTitleBlock entity
626 * @projection: the new projection
628 * Sets a new projection symbol on the title block. This function
629 * will add a reference to @projection, removing the eventual
630 * reference held to the old symbol, hence possibly destroying
633 * The space reserved for the projection is 56x56, so try to keep the
634 * new projection near this size or scale it accordingly.
639 adg_title_block_set_projection(AdgTitleBlock
*title_block
,
640 AdgEntity
*projection
)
642 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block
));
643 g_object_set(title_block
, "projection", projection
, NULL
);
647 * adg_title_block_projection:
648 * @title_block: an #AdgTitleBlock entity
650 * Gets the projection bound to this title block.
651 * The returned object is owned by @title_block and should not
652 * be unreferenced although can be freely modified.
654 * Returns: (transfer none): the projection or <constant>NULL</constant> on no projection or errors.
659 adg_title_block_projection(AdgTitleBlock
*title_block
)
661 AdgTitleBlockPrivate
*data
;
663 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block
), NULL
);
665 data
= adg_title_block_get_instance_private(title_block
);
666 return data
->projection
;