1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007,2008,2009 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.
37 * All fields are privates and should not be used directly.
38 * Use its public methods instead.
42 #include "adg-title-block.h"
43 #include "adg-title-block-private.h"
46 #define PARENT_OBJECT_CLASS ((GObjectClass *) adg_title_block_parent_class)
47 #define PARENT_ENTITY_CLASS ((AdgEntityClass *) adg_title_block_parent_class)
63 static void dispose (GObject
*object
);
64 static void finalize (GObject
*object
);
65 static void get_property (GObject
*object
,
69 static void set_property (GObject
*object
,
73 static AdgTable
* get_table (AdgTitleBlock
*title_block
);
74 static gboolean
set_title (AdgTitleBlock
*title_block
,
76 static gboolean
set_drawing (AdgTitleBlock
*title_block
,
77 const gchar
*drawing
);
78 static gboolean
set_size (AdgTitleBlock
*title_block
,
80 static gboolean
set_scale (AdgTitleBlock
*title_block
,
82 static gboolean
set_author (AdgTitleBlock
*title_block
,
84 static gboolean
set_date (AdgTitleBlock
*title_block
,
86 static gboolean
set_logo (AdgTitleBlock
*title_block
,
88 static gboolean
set_projection (AdgTitleBlock
*title_block
,
89 AdgEntity
*projection
);
92 G_DEFINE_TYPE(AdgTitleBlock
, adg_title_block
, ADG_TYPE_TABLE
);
96 adg_title_block_class_init(AdgTitleBlockClass
*klass
)
98 GObjectClass
*gobject_class
;
101 gobject_class
= (GObjectClass
*) klass
;
103 g_type_class_add_private(klass
, sizeof(AdgTitleBlockPrivate
));
105 gobject_class
->dispose
= dispose
;
106 gobject_class
->finalize
= finalize
;
107 gobject_class
->set_property
= set_property
;
108 gobject_class
->get_property
= get_property
;
110 param
= g_param_spec_string("title",
112 P_("A descriptive title of the drawing"),
115 g_object_class_install_property(gobject_class
, PROP_TITLE
, param
);
117 param
= g_param_spec_string("drawing",
119 P_("The name of the drawing: the ADG canvas does not make any assumtpion on this text string"),
122 g_object_class_install_property(gobject_class
, PROP_DRAWING
, param
);
124 param
= g_param_spec_string("size",
126 P_("The media size to be used to print the drawing, usually something like \"A3\" or \"Letter\""),
129 g_object_class_install_property(gobject_class
, PROP_SIZE
, param
);
131 param
= g_param_spec_string("scale",
133 P_("The scale of the drawing, if it makes sense"),
136 g_object_class_install_property(gobject_class
, PROP_SCALE
, param
);
138 param
= g_param_spec_string("author",
140 P_("Name and last name of the author of the drawing"),
143 g_object_class_install_property(gobject_class
, PROP_AUTHOR
, param
);
145 param
= g_param_spec_string("date",
147 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"),
150 g_object_class_install_property(gobject_class
, PROP_DATE
, param
);
152 param
= g_param_spec_object("logo",
154 P_("An entity to be displayed in the title block as the logo of the owner: the containing cell has a 1:1 ratio"),
157 g_object_class_install_property(gobject_class
, PROP_LOGO
, param
);
159 param
= g_param_spec_object("projection",
160 P_("Projection Scheme"),
161 P_("The entity usually reserved to identify the projection scheme adopted by this drawing"),
164 g_object_class_install_property(gobject_class
, PROP_PROJECTION
, param
);
168 adg_title_block_init(AdgTitleBlock
*title_block
)
170 AdgTitleBlockPrivate
*data
= G_TYPE_INSTANCE_GET_PRIVATE(title_block
,
171 ADG_TYPE_TITLE_BLOCK
,
172 AdgTitleBlockPrivate
);
175 data
->drawing
= NULL
;
180 data
->projection
= NULL
;
182 title_block
->data
= data
;
186 dispose(GObject
*object
)
188 AdgTitleBlockPrivate
*data
= ((AdgTitleBlock
*) object
)->data
;
190 if (data
->logo
!= NULL
) {
191 g_object_unref(data
->logo
);
195 if (data
->projection
!= NULL
) {
196 g_object_unref(data
->projection
);
197 data
->projection
= NULL
;
200 if (PARENT_OBJECT_CLASS
->dispose
!= NULL
)
201 PARENT_OBJECT_CLASS
->dispose(object
);
205 finalize(GObject
*object
)
207 AdgTitleBlockPrivate
*data
= ((AdgTitleBlock
*) object
)->data
;
210 g_free(data
->drawing
);
213 g_free(data
->author
);
216 if (PARENT_OBJECT_CLASS
->finalize
!= NULL
)
217 PARENT_OBJECT_CLASS
->finalize(object
);
221 get_property(GObject
*object
,
222 guint prop_id
, GValue
*value
, GParamSpec
*pspec
)
224 AdgTitleBlockPrivate
*data
= ((AdgTitleBlock
*) object
)->data
;
228 g_value_set_string(value
, data
->title
);
231 g_value_set_string(value
, data
->drawing
);
234 g_value_set_string(value
, data
->size
);
237 g_value_set_string(value
, data
->scale
);
240 g_value_set_string(value
, data
->author
);
243 g_value_set_string(value
, data
->date
);
246 g_value_set_object(value
, data
->logo
);
248 case PROP_PROJECTION
:
249 g_value_set_object(value
, data
->projection
);
252 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
258 set_property(GObject
*object
,
259 guint prop_id
, const GValue
*value
, GParamSpec
*pspec
)
261 AdgTitleBlock
*title_block
= (AdgTitleBlock
*) object
;
265 set_title(title_block
, g_value_get_string(value
));
268 set_drawing(title_block
, g_value_get_string(value
));
271 set_size(title_block
, g_value_get_string(value
));
274 set_scale(title_block
, g_value_get_string(value
));
277 set_author(title_block
, g_value_get_string(value
));
280 set_date(title_block
, g_value_get_string(value
));
283 set_logo(title_block
, g_value_get_object(value
));
285 case PROP_PROJECTION
:
286 set_projection(title_block
, g_value_get_object(value
));
289 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
296 * adg_title_block_new:
298 * Creates a new empty title block entity. The #AdgEntity:local-method
299 * property is set by default to #ADG_MIX_DISABLED, that is the
300 * title block is not subject to any local transformations.
302 * Returns: the newly created title block entity
305 adg_title_block_new(void)
307 return g_object_new(ADG_TYPE_TITLE_BLOCK
,
308 "local-method", ADG_MIX_DISABLED
, NULL
);
312 * adg_title_block_get_title:
313 * @title_block: an #AdgTitleBlock entity
315 * Gets the descriptive title associated to this title block.
316 * The returned string is owned by @title_block and should not
317 * be modifed or freed.
319 * Returns: the title or %NULL on no title or errors
322 adg_title_block_get_title(AdgTitleBlock
*title_block
)
324 AdgTitleBlockPrivate
*data
;
326 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block
), NULL
);
328 data
= title_block
->data
;
334 * adg_title_block_set_title:
335 * @title_block: an #AdgTitleBlock entity
336 * @title: the new title
338 * Sets a new title on the title block.
341 adg_title_block_set_title(AdgTitleBlock
*title_block
, const gchar
*title
)
343 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block
));
345 if (set_title(title_block
, title
))
346 g_object_notify((GObject
*) title_block
, "title");
350 * adg_title_block_get_drawing:
351 * @title_block: an #AdgTitleBlock entity
353 * Gets the drawing name, commonly used to specify the file name.
354 * The returned string is owned by @title_block and should not
355 * be modifed or freed.
357 * Returns: the drawing name or %NULL on no name or errors
360 adg_title_block_get_drawing(AdgTitleBlock
*title_block
)
362 AdgTitleBlockPrivate
*data
;
364 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block
), NULL
);
366 data
= title_block
->data
;
368 return data
->drawing
;
372 * adg_title_block_set_drawing:
373 * @title_block: an #AdgTitleBlock entity
374 * @drawing: the new drawing name
376 * Sets a new drawing name on the title block.
379 adg_title_block_set_drawing(AdgTitleBlock
*title_block
, const gchar
*drawing
)
381 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block
));
383 if (set_drawing(title_block
, drawing
))
384 g_object_notify((GObject
*) title_block
, "drawing");
388 * adg_title_block_get_size:
389 * @title_block: an #AdgTitleBlock entity
391 * Gets the media size (a descriptive name) where this drawing will
392 * be printed. Usually contains something like "A4" or "Letter".
393 * The returned string is owned by @title_block and should not
394 * be modifed or freed.
396 * Returns: the size or %NULL on no size or errors
399 adg_title_block_get_size(AdgTitleBlock
*title_block
)
401 AdgTitleBlockPrivate
*data
;
403 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block
), NULL
);
405 data
= title_block
->data
;
411 * adg_title_block_set_size:
412 * @title_block: an #AdgTitleBlock entity
413 * @size: the new size
415 * Sets a new size on the title block.
418 adg_title_block_set_size(AdgTitleBlock
*title_block
, const gchar
*size
)
420 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block
));
422 if (set_size(title_block
, size
))
423 g_object_notify((GObject
*) title_block
, "size");
427 * adg_title_block_get_scale:
428 * @title_block: an #AdgTitleBlock entity
430 * Gets the scale descriptive name of the drawing.
432 * Returns: the scale text or %NULL on no scale or errors
435 adg_title_block_get_scale(AdgTitleBlock
*title_block
)
437 AdgTitleBlockPrivate
*data
;
439 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block
), NULL
);
441 data
= title_block
->data
;
447 * adg_title_block_set_scale:
448 * @title_block: an #AdgTitleBlock entity
449 * @scale: the new scale
451 * Sets a new scale on the title block.
454 adg_title_block_set_scale(AdgTitleBlock
*title_block
, const gchar
*scale
)
456 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block
));
458 if (set_scale(title_block
, scale
))
459 g_object_notify((GObject
*) title_block
, "scale");
463 * adg_title_block_get_author:
464 * @title_block: an #AdgTitleBlock entity
466 * Gets the author's name of the drawing.
468 * Returns: the author or %NULL on no author or errors
471 adg_title_block_get_author(AdgTitleBlock
*title_block
)
473 AdgTitleBlockPrivate
*data
;
475 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block
), NULL
);
477 data
= title_block
->data
;
483 * adg_title_block_set_author:
484 * @title_block: an #AdgTitleBlock entity
485 * @author: the new author
487 * Sets a new author on the title block.
490 adg_title_block_set_author(AdgTitleBlock
*title_block
, const gchar
*author
)
492 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block
));
494 if (set_author(title_block
, author
))
495 g_object_notify((GObject
*) title_block
, "author");
499 * adg_title_block_get_date:
500 * @title_block: an #AdgTitleBlock entity
502 * Gets the date of the rendering set on @title_block.
504 * Returns: the date or %NULL on no date or errors
507 adg_title_block_get_date(AdgTitleBlock
*title_block
)
509 AdgTitleBlockPrivate
*data
;
511 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block
), NULL
);
513 data
= title_block
->data
;
519 * adg_title_block_set_date:
520 * @title_block: an #AdgTitleBlock entity
521 * @date: the new date
523 * Sets a new date on the title block. By default the date is set
524 * to %NULL (so no date will be rendered) but setting it to an
525 * empty string (that is, %"") will implicitely set the date to
526 * today, by using the preferred representation for the current
527 * local. This will give a result roughly equivalent to:
530 * strftime(buffer, sizeof(buffer), "%x", now);
534 adg_title_block_set_date(AdgTitleBlock
*title_block
, const gchar
*date
)
536 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block
));
538 if (set_date(title_block
, date
))
539 g_object_notify((GObject
*) title_block
, "date");
543 * adg_title_block_get_logo:
544 * @title_block: an #AdgTitleBlock entity
546 * Gets the logo bound to this title block.
547 * The returned object is owned by @title_block and should not
548 * be unreferenced although can be freely modified.
550 * Returns: the logo or %NULL on no logo or errors
553 adg_title_block_get_logo(AdgTitleBlock
*title_block
)
555 AdgTitleBlockPrivate
*data
;
557 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block
), NULL
);
559 data
= title_block
->data
;
565 * adg_title_block_set_logo:
566 * @title_block: an #AdgTitleBlock entity
567 * @logo: the new logo
569 * Sets a new logo on the title block. This function will add
570 * a reference to @logo, removing the eventual reference held
571 * to the old logo, hence possibly destroying the old endity.
573 * The space reserved for the logo is 56x56, so try to keep the
574 * new logo near this size or scale it accordingly.
577 adg_title_block_set_logo(AdgTitleBlock
*title_block
, AdgEntity
*logo
)
579 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block
));
581 if (set_logo(title_block
, logo
))
582 g_object_notify((GObject
*) title_block
, "logo");
586 * adg_title_block_get_projection:
587 * @title_block: an #AdgTitleBlock entity
589 * Gets the projection bound to this title block.
590 * The returned object is owned by @title_block and should not
591 * be unreferenced although can be freely modified.
593 * Returns: the projection or %NULL on no projection or errors
596 adg_title_block_get_projection(AdgTitleBlock
*title_block
)
598 AdgTitleBlockPrivate
*data
;
600 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block
), NULL
);
602 data
= title_block
->data
;
604 return data
->projection
;
608 * adg_title_block_set_projection:
609 * @title_block: an #AdgTitleBlock entity
610 * @projection: the new projection
612 * Sets a new projection symbol on the title block. This function
613 * will add a reference to @projection, removing the eventual
614 * reference held to the old symbol, hence possibly destroying
617 * The space reserved for the projection is 56x56, so try to keep the
618 * new projection near this size or scale it accordingly.
621 adg_title_block_set_projection(AdgTitleBlock
*title_block
,
622 AdgEntity
*projection
)
624 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block
));
626 if (set_projection(title_block
, projection
))
627 g_object_notify((GObject
*) title_block
, "projection");
632 get_table(AdgTitleBlock
*title_block
)
634 AdgTable
*table
= (AdgTable
*) title_block
;
636 if (adg_table_get_n_rows(table
) == 0) {
641 row
= adg_table_row_new(table
);
643 cell
= adg_table_cell_new(row
, 62);
645 cell
= adg_table_cell_new(row
, 200);
646 adg_table_cell_set_name(cell
, "title");
647 adg_table_cell_set_text_title(cell
, _("TITLE"));
648 adg_table_cell_switch_frame(cell
, TRUE
);
651 row
= adg_table_row_new(table
);
653 cell
= adg_table_cell_new(row
, 62);
654 adg_table_cell_set_name(cell
, "logo");
656 cell
= adg_table_cell_new(row
, 40);
657 adg_table_cell_set_name(cell
, "size");
658 adg_table_cell_set_text_title(cell
, _("SIZE"));
659 adg_table_cell_switch_frame(cell
, TRUE
);
661 cell
= adg_table_cell_new(row
, 60);
662 adg_table_cell_set_name(cell
, "scale");
663 adg_table_cell_set_text_title(cell
, _("SCALE"));
664 adg_table_cell_switch_frame(cell
, TRUE
);
666 cell
= adg_table_cell_new(row
, 100);
667 adg_table_cell_set_name(cell
, "drawing");
668 adg_table_cell_set_text_title(cell
, _("DRAWING"));
669 adg_table_cell_switch_frame(cell
, TRUE
);
672 row
= adg_table_row_new(table
);
674 cell
= adg_table_cell_new(row
, 62);
675 adg_table_cell_set_name(cell
, "projection");
676 adg_table_cell_switch_frame(cell
, TRUE
);
678 cell
= adg_table_cell_new(row
, 100);
679 adg_table_cell_set_name(cell
, "author");
680 adg_table_cell_set_text_title(cell
, _("AUTHOR"));
681 adg_table_cell_switch_frame(cell
, TRUE
);
683 cell
= adg_table_cell_new(row
, 100);
684 adg_table_cell_set_name(cell
, "date");
685 adg_table_cell_set_text_title(cell
, _("DATE"));
686 adg_table_cell_switch_frame(cell
, TRUE
);
693 set_title(AdgTitleBlock
*title_block
, const gchar
*title
)
695 AdgTitleBlockPrivate
*data
;
699 data
= title_block
->data
;
701 if (adg_strcmp(title
, data
->title
) == 0)
705 data
->title
= g_strdup(title
);
707 table
= get_table(title_block
);
708 cell
= adg_table_get_cell(table
, "title");
709 adg_table_cell_set_text_value(cell
, data
->title
);
714 set_drawing(AdgTitleBlock
*title_block
, const gchar
*drawing
)
716 AdgTitleBlockPrivate
*data
;
720 data
= title_block
->data
;
722 if (adg_strcmp(drawing
, data
->drawing
) == 0)
725 g_free(data
->drawing
);
726 data
->drawing
= g_strdup(drawing
);
728 table
= get_table(title_block
);
729 cell
= adg_table_get_cell(table
, "drawing");
730 adg_table_cell_set_text_value(cell
, data
->drawing
);
735 set_size(AdgTitleBlock
*title_block
, const gchar
*size
)
737 AdgTitleBlockPrivate
*data
;
741 data
= title_block
->data
;
743 if (adg_strcmp(size
, data
->size
) == 0)
747 data
->size
= g_strdup(size
);
749 table
= get_table(title_block
);
750 cell
= adg_table_get_cell(table
, "size");
751 adg_table_cell_set_text_value(cell
, data
->size
);
756 set_scale(AdgTitleBlock
*title_block
, const gchar
*scale
)
758 AdgTitleBlockPrivate
*data
;
762 data
= title_block
->data
;
764 if (adg_strcmp(scale
, data
->scale
) == 0)
768 data
->scale
= g_strdup(scale
);
770 table
= get_table(title_block
);
771 cell
= adg_table_get_cell(table
, "scale");
772 adg_table_cell_set_text_value(cell
, data
->scale
);
777 set_author(AdgTitleBlock
*title_block
, const gchar
*author
)
779 AdgTitleBlockPrivate
*data
;
783 data
= title_block
->data
;
785 if (adg_strcmp(author
, data
->author
) == 0)
788 g_free(data
->author
);
789 data
->author
= g_strdup(author
);
791 table
= get_table(title_block
);
792 cell
= adg_table_get_cell(table
, "author");
793 adg_table_cell_set_text_value(cell
, data
->author
);
798 set_date(AdgTitleBlock
*title_block
, const gchar
*date
)
800 AdgTitleBlockPrivate
*data
;
804 data
= title_block
->data
;
806 if (adg_strcmp(date
, data
->date
) == 0)
811 if (date
!= NULL
&& date
[0] == '\0') {
812 /* The date must be automatically updated */
814 char buffer
[100] = { 0 };
816 gdate
= g_date_new();
817 g_date_set_time_t(gdate
, time (NULL
));
818 g_date_strftime(buffer
, sizeof(buffer
), "%x", gdate
);
821 data
->date
= g_strdup(buffer
);
823 data
->date
= g_strdup(date
);
826 table
= get_table(title_block
);
827 cell
= adg_table_get_cell(table
, "date");
828 adg_table_cell_set_text_value(cell
, data
->date
);
833 set_logo(AdgTitleBlock
*title_block
, AdgEntity
*logo
)
835 AdgTitleBlockPrivate
*data
;
839 data
= title_block
->data
;
841 if (logo
== data
->logo
)
844 if (data
->logo
!= NULL
)
845 g_object_unref(data
->logo
);
849 if (data
->logo
!= NULL
)
850 g_object_ref_sink(data
->logo
);
852 table
= get_table(title_block
);
853 cell
= adg_table_get_cell(table
, "logo");
854 adg_table_cell_set_value(cell
, data
->logo
);
859 set_projection(AdgTitleBlock
*title_block
, AdgEntity
*projection
)
861 AdgTitleBlockPrivate
*data
;
865 data
= title_block
->data
;
867 if (projection
== data
->projection
)
870 if (data
->projection
!= NULL
)
871 g_object_unref(data
->projection
);
873 data
->projection
= projection
;
875 if (data
->projection
!= NULL
)
876 g_object_ref_sink(data
->projection
);
878 table
= get_table(title_block
);
879 cell
= adg_table_get_cell(table
, "projection");
880 adg_table_cell_set_value(cell
, data
->projection
);