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(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 g_type_class_add_private(klass
, sizeof(AdgTitleBlockPrivate
));
95 gobject_class
->finalize
= _adg_finalize
;
96 gobject_class
->set_property
= _adg_set_property
;
97 gobject_class
->get_property
= _adg_get_property
;
99 param
= g_param_spec_string("title",
101 P_("A descriptive title of the drawing"),
104 g_object_class_install_property(gobject_class
, PROP_TITLE
, param
);
106 param
= g_param_spec_string("drawing",
108 P_("The name of the drawing: the ADG canvas does not make any assumtpion on this text string"),
111 g_object_class_install_property(gobject_class
, PROP_DRAWING
, param
);
113 param
= g_param_spec_string("size",
115 P_("The media size to be used to print the drawing, usually something like \"A3\" or \"Letter\""),
118 g_object_class_install_property(gobject_class
, PROP_SIZE
, param
);
120 param
= g_param_spec_string("scale",
122 P_("The scale of the drawing, if it makes sense"),
125 g_object_class_install_property(gobject_class
, PROP_SCALE
, param
);
127 param
= g_param_spec_string("author",
129 P_("Name and last name of the author of the drawing"),
132 g_object_class_install_property(gobject_class
, PROP_AUTHOR
, param
);
134 param
= g_param_spec_string("date",
136 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"),
139 g_object_class_install_property(gobject_class
, PROP_DATE
, param
);
141 param
= g_param_spec_object("logo",
143 P_("An entity to be displayed in the title block as the logo of the owner: the containing cell has a 1:1 ratio"),
146 g_object_class_install_property(gobject_class
, PROP_LOGO
, param
);
148 param
= g_param_spec_object("projection",
149 P_("Projection Scheme"),
150 P_("The entity usually reserved to identify the projection scheme adopted by this drawing"),
153 g_object_class_install_property(gobject_class
, PROP_PROJECTION
, param
);
157 adg_title_block_init(AdgTitleBlock
*title_block
)
159 AdgTable
*table
= (AdgTable
*) title_block
;
161 AdgTitleBlockPrivate
*data
= G_TYPE_INSTANCE_GET_PRIVATE(title_block
,
162 ADG_TYPE_TITLE_BLOCK
,
163 AdgTitleBlockPrivate
);
167 data
->drawing
= NULL
;
172 data
->projection
= NULL
;
174 title_block
->data
= data
;
176 /* By default the title block should be floating */
177 adg_entity_switch_floating((AdgEntity
*) title_block
, TRUE
);
179 /* Create the title block template*/
182 row
= adg_table_row_new(table
);
183 adg_table_cell_new_with_width(row
, 62);
184 adg_table_cell_new_full(row
, 200, "title", _("TITLE"), TRUE
);
187 row
= adg_table_row_new(table
);
188 adg_table_cell_new_full(row
, 62, "logo", NULL
, FALSE
);
189 adg_table_cell_new_full(row
, 40, "size", _("SIZE"), TRUE
);
190 adg_table_cell_new_full(row
, 60, "scale", _("SCALE"), TRUE
);
191 adg_table_cell_new_full(row
, 100, "drawing", _("DRAWING"), TRUE
);
194 row
= adg_table_row_new(table
);
195 adg_table_cell_new_full(row
, 62, "projection", NULL
, TRUE
);
196 adg_table_cell_new_full(row
, 100, "author", _("AUTHOR"), TRUE
);
197 adg_table_cell_new_full(row
, 100, "date", _("DATE"), TRUE
);
201 _adg_finalize(GObject
*object
)
203 AdgTitleBlockPrivate
*data
= ((AdgTitleBlock
*) object
)->data
;
206 g_free(data
->drawing
);
209 g_free(data
->author
);
212 if (_ADG_OLD_OBJECT_CLASS
->finalize
)
213 _ADG_OLD_OBJECT_CLASS
->finalize(object
);
217 _adg_get_property(GObject
*object
, guint prop_id
,
218 GValue
*value
, GParamSpec
*pspec
)
220 AdgTitleBlockPrivate
*data
= ((AdgTitleBlock
*) object
)->data
;
224 g_value_set_string(value
, data
->title
);
227 g_value_set_string(value
, data
->drawing
);
230 g_value_set_string(value
, data
->size
);
233 g_value_set_string(value
, data
->scale
);
236 g_value_set_string(value
, data
->author
);
239 g_value_set_string(value
, data
->date
);
242 g_value_set_object(value
, data
->logo
);
244 case PROP_PROJECTION
:
245 g_value_set_object(value
, data
->projection
);
248 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
254 _adg_set_property(GObject
*object
, guint prop_id
,
255 const GValue
*value
, GParamSpec
*pspec
)
257 AdgTitleBlock
*title_block
;
258 AdgTitleBlockPrivate
*data
;
262 title_block
= (AdgTitleBlock
*) object
;
263 data
= title_block
->data
;
264 table
= (AdgTable
*) object
;
269 data
->title
= g_value_dup_string(value
);
270 cell
= adg_table_get_cell(table
, "title");
271 adg_table_cell_set_text_value(cell
, data
->title
);
274 g_free(data
->drawing
);
275 data
->drawing
= g_value_dup_string(value
);
276 cell
= adg_table_get_cell(table
, "drawing");
277 adg_table_cell_set_text_value(cell
, data
->drawing
);
281 data
->size
= g_value_dup_string(value
);
282 cell
= adg_table_get_cell(table
, "size");
283 adg_table_cell_set_text_value(cell
, data
->size
);
287 data
->scale
= g_value_dup_string(value
);
288 cell
= adg_table_get_cell(table
, "scale");
289 adg_table_cell_set_text_value(cell
, data
->scale
);
292 g_free(data
->author
);
293 data
->author
= g_value_dup_string(value
);
294 cell
= adg_table_get_cell(table
, "author");
295 adg_table_cell_set_text_value(cell
, data
->author
);
299 if (g_value_get_string(value
) == NULL
) {
300 /* NULL means the date must be automatically updated */
302 char buffer
[100] = { 0 };
304 gdate
= g_date_new();
305 g_date_set_time_t(gdate
, time (NULL
));
306 g_date_strftime(buffer
, sizeof(buffer
), "%x", gdate
);
309 data
->date
= g_strdup(buffer
);
311 data
->date
= g_value_dup_string(value
);
313 cell
= adg_table_get_cell(table
, "date");
314 adg_table_cell_set_text_value(cell
, data
->date
);
317 data
->logo
= g_value_get_object(value
);
318 cell
= adg_table_get_cell(table
, "logo");
319 adg_table_cell_set_value(cell
, data
->logo
);
320 adg_table_cell_set_value_pos_explicit(cell
, 0.5, 1, 0.5, 0.5);
322 case PROP_PROJECTION
:
323 data
->projection
= g_value_get_object(value
);
324 cell
= adg_table_get_cell(table
, "projection");
325 adg_table_cell_set_value(cell
, data
->projection
);
326 adg_table_cell_set_value_pos_explicit(cell
, 0.5, 0.5, 0.5, 0.5);
329 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
336 * adg_title_block_new:
338 * Creates a new empty title block entity.
340 * Returns: (transfer full): the newly created title block entity.
345 adg_title_block_new(void)
347 return g_object_new(ADG_TYPE_TITLE_BLOCK
, NULL
);
351 * adg_title_block_set_title:
352 * @title_block: an #AdgTitleBlock entity
353 * @title: the new title
355 * Sets a new title on the title block.
360 adg_title_block_set_title(AdgTitleBlock
*title_block
, const gchar
*title
)
362 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block
));
363 g_object_set(title_block
, "title", title
, NULL
);
367 * adg_title_block_get_title:
368 * @title_block: an #AdgTitleBlock entity
370 * Gets the descriptive title associated to this title block.
371 * The returned string is owned by @title_block and should not
372 * be modifed or freed.
374 * Returns: (transfer none): the title or <constant>NULL</constant> on no title or errors.
379 adg_title_block_get_title(AdgTitleBlock
*title_block
)
381 AdgTitleBlockPrivate
*data
;
383 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block
), NULL
);
385 data
= title_block
->data
;
391 * adg_title_block_set_drawing:
392 * @title_block: an #AdgTitleBlock entity
393 * @drawing: the new drawing name
395 * Sets a new drawing name on the title block.
400 adg_title_block_set_drawing(AdgTitleBlock
*title_block
, const gchar
*drawing
)
402 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block
));
403 g_object_set(title_block
, "drawing", drawing
, NULL
);
407 * adg_title_block_get_drawing:
408 * @title_block: an #AdgTitleBlock entity
410 * Gets the drawing name, commonly used to specify the file name.
411 * The returned string is owned by @title_block and should not
412 * be modifed or freed.
414 * Returns: (transfer none): the drawing name or <constant>NULL</constant> on no name or errors.
419 adg_title_block_get_drawing(AdgTitleBlock
*title_block
)
421 AdgTitleBlockPrivate
*data
;
423 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block
), NULL
);
425 data
= title_block
->data
;
427 return data
->drawing
;
431 * adg_title_block_set_size:
432 * @title_block: an #AdgTitleBlock entity
433 * @size: the new size
435 * Sets a new size on the title block.
440 adg_title_block_set_size(AdgTitleBlock
*title_block
, const gchar
*size
)
442 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block
));
443 g_object_set(title_block
, "size", size
, NULL
);
447 * adg_title_block_get_size:
448 * @title_block: an #AdgTitleBlock entity
450 * Gets the media size (a descriptive name) where this drawing will
451 * be printed. Usually contains something like <constant>"A4"</constant>
452 * or <constant>"Letter"</constant>.
453 * The returned string is owned by @title_block and should not
454 * be modifed or freed.
456 * Returns: (transfer none): the size or <constant>NULL</constant> on no size or errors.
461 adg_title_block_get_size(AdgTitleBlock
*title_block
)
463 AdgTitleBlockPrivate
*data
;
465 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block
), NULL
);
467 data
= title_block
->data
;
473 * adg_title_block_set_scale:
474 * @title_block: an #AdgTitleBlock entity
475 * @scale: the new scale
477 * Sets a new scale on the title block.
482 adg_title_block_set_scale(AdgTitleBlock
*title_block
, const gchar
*scale
)
484 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block
));
485 g_object_set(title_block
, "scale", scale
, NULL
);
489 * adg_title_block_get_scale:
490 * @title_block: an #AdgTitleBlock entity
492 * Gets the scale descriptive name of the drawing.
494 * Returns: (transfer none): the scale text or <constant>NULL</constant> on no scale or errors.
499 adg_title_block_get_scale(AdgTitleBlock
*title_block
)
501 AdgTitleBlockPrivate
*data
;
503 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block
), NULL
);
505 data
= title_block
->data
;
511 * adg_title_block_set_author:
512 * @title_block: an #AdgTitleBlock entity
513 * @author: the new author
515 * Sets a new author on the title block.
520 adg_title_block_set_author(AdgTitleBlock
*title_block
, const gchar
*author
)
522 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block
));
523 g_object_set(title_block
, "author", author
, NULL
);
527 * adg_title_block_get_author:
528 * @title_block: an #AdgTitleBlock entity
530 * Gets the author's name of the drawing.
532 * Returns: (transfer none): the author or <constant>NULL</constant> on no author or errors.
537 adg_title_block_get_author(AdgTitleBlock
*title_block
)
539 AdgTitleBlockPrivate
*data
;
541 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block
), NULL
);
543 data
= title_block
->data
;
549 * adg_title_block_set_date:
550 * @title_block: an #AdgTitleBlock entity
551 * @date: the new date
553 * Sets a new date on the title block. By default the date is
554 * set to <constant>NULL</constant> and it will be implicitely
555 * rendered using the*preferred representation for the current
556 * local of the actual date. This is roughly equivalent to:
558 * <informalexample><programlisting language="C">
559 * strftime(buffer, sizeof(buffer), "%x", now);
560 * adg_title_block_set_date(title_block, buffer);
561 * </programlisting></informalexample>
563 * To not render any value, use an empty string as @date.
568 adg_title_block_set_date(AdgTitleBlock
*title_block
, const gchar
*date
)
570 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block
));
571 g_object_set(title_block
, "date", date
, NULL
);
575 * adg_title_block_get_date:
576 * @title_block: an #AdgTitleBlock entity
578 * Gets the date of the rendering set on @title_block.
580 * Returns: (transfer none): the date or <constant>NULL</constant> on no date or errors.
585 adg_title_block_get_date(AdgTitleBlock
*title_block
)
587 AdgTitleBlockPrivate
*data
;
589 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block
), NULL
);
591 data
= title_block
->data
;
597 * adg_title_block_set_logo:
598 * @title_block: an #AdgTitleBlock entity
599 * @logo: the new logo
601 * Sets a new logo on the title block. This function will add
602 * a reference to @logo, removing the eventual reference held
603 * to the old logo, hence possibly destroying the old endity.
605 * The space reserved for the logo is 56x56, so try to keep the
606 * new logo near this size or scale it accordingly.
611 adg_title_block_set_logo(AdgTitleBlock
*title_block
, AdgEntity
*logo
)
613 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block
));
614 g_object_set(title_block
, "logo", logo
, NULL
);
618 * adg_title_block_logo:
619 * @title_block: an #AdgTitleBlock entity
621 * Gets the logo bound to this title block.
622 * The returned object is owned by @title_block and should not
623 * be unreferenced although can be freely modified.
625 * Returns: (transfer none): the logo or <constant>NULL</constant> on no logo or errors.
630 adg_title_block_logo(AdgTitleBlock
*title_block
)
632 AdgTitleBlockPrivate
*data
;
634 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block
), NULL
);
636 data
= title_block
->data
;
642 * adg_title_block_set_projection:
643 * @title_block: an #AdgTitleBlock entity
644 * @projection: the new projection
646 * Sets a new projection symbol on the title block. This function
647 * will add a reference to @projection, removing the eventual
648 * reference held to the old symbol, hence possibly destroying
651 * The space reserved for the projection is 56x56, so try to keep the
652 * new projection near this size or scale it accordingly.
657 adg_title_block_set_projection(AdgTitleBlock
*title_block
,
658 AdgEntity
*projection
)
660 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block
));
661 g_object_set(title_block
, "projection", projection
, NULL
);
665 * adg_title_block_projection:
666 * @title_block: an #AdgTitleBlock entity
668 * Gets the projection bound to this title block.
669 * The returned object is owned by @title_block and should not
670 * be unreferenced although can be freely modified.
672 * Returns: (transfer none): the projection or <constant>NULL</constant> on no projection or errors.
677 adg_title_block_projection(AdgTitleBlock
*title_block
)
679 AdgTitleBlockPrivate
*data
;
681 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block
), NULL
);
683 data
= title_block
->data
;
685 return data
->projection
;