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 finalize (GObject
*object
);
64 static void get_property (GObject
*object
,
68 static void set_property (GObject
*object
,
72 static AdgTable
* get_table (AdgTitleBlock
*title_block
);
73 static gboolean
set_title (AdgTitleBlock
*title_block
,
75 static gboolean
set_drawing (AdgTitleBlock
*title_block
,
76 const gchar
*drawing
);
77 static gboolean
set_size (AdgTitleBlock
*title_block
,
79 static gboolean
set_scale (AdgTitleBlock
*title_block
,
81 static gboolean
set_author (AdgTitleBlock
*title_block
,
83 static gboolean
set_date (AdgTitleBlock
*title_block
,
85 static gboolean
set_logo (AdgTitleBlock
*title_block
,
87 static gboolean
set_projection (AdgTitleBlock
*title_block
,
88 AdgEntity
*projection
);
91 G_DEFINE_TYPE(AdgTitleBlock
, adg_title_block
, ADG_TYPE_TABLE
);
95 adg_title_block_class_init(AdgTitleBlockClass
*klass
)
97 GObjectClass
*gobject_class
;
100 gobject_class
= (GObjectClass
*) klass
;
102 g_type_class_add_private(klass
, sizeof(AdgTitleBlockPrivate
));
104 gobject_class
->finalize
= finalize
;
105 gobject_class
->set_property
= set_property
;
106 gobject_class
->get_property
= get_property
;
108 param
= g_param_spec_string("title",
110 P_("A descriptive title of the drawing"),
113 g_object_class_install_property(gobject_class
, PROP_TITLE
, param
);
115 param
= g_param_spec_string("drawing",
117 P_("The name of the drawing: the ADG canvas does not make any assumtpion on this text string"),
120 g_object_class_install_property(gobject_class
, PROP_DRAWING
, param
);
122 param
= g_param_spec_string("size",
124 P_("The media size to be used to print the drawing, usually something like \"A3\" or \"Letter\""),
127 g_object_class_install_property(gobject_class
, PROP_SIZE
, param
);
129 param
= g_param_spec_string("scale",
131 P_("The scale of the drawing, if it makes sense"),
134 g_object_class_install_property(gobject_class
, PROP_SCALE
, param
);
136 param
= g_param_spec_string("author",
138 P_("Name and last name of the author of the drawing"),
141 g_object_class_install_property(gobject_class
, PROP_AUTHOR
, param
);
143 param
= g_param_spec_string("date",
145 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"),
148 g_object_class_install_property(gobject_class
, PROP_DATE
, param
);
150 param
= g_param_spec_object("logo",
152 P_("An entity to be displayed in the title block as the logo of the owner: the containing cell has a 1:1 ratio"),
155 g_object_class_install_property(gobject_class
, PROP_LOGO
, param
);
157 param
= g_param_spec_object("projection",
158 P_("Projection Scheme"),
159 P_("The entity usually reserved to identify the projection scheme adopted by this drawing"),
162 g_object_class_install_property(gobject_class
, PROP_PROJECTION
, param
);
166 adg_title_block_init(AdgTitleBlock
*title_block
)
168 AdgTitleBlockPrivate
*data
= G_TYPE_INSTANCE_GET_PRIVATE(title_block
,
169 ADG_TYPE_TITLE_BLOCK
,
170 AdgTitleBlockPrivate
);
173 data
->drawing
= NULL
;
178 data
->projection
= NULL
;
180 title_block
->data
= data
;
184 finalize(GObject
*object
)
186 AdgTitleBlockPrivate
*data
= ((AdgTitleBlock
*) object
)->data
;
189 g_free(data
->drawing
);
192 g_free(data
->author
);
195 if (PARENT_OBJECT_CLASS
->finalize
)
196 PARENT_OBJECT_CLASS
->finalize(object
);
200 get_property(GObject
*object
,
201 guint prop_id
, GValue
*value
, GParamSpec
*pspec
)
203 AdgTitleBlockPrivate
*data
= ((AdgTitleBlock
*) object
)->data
;
207 g_value_set_string(value
, data
->title
);
210 g_value_set_string(value
, data
->drawing
);
213 g_value_set_string(value
, data
->size
);
216 g_value_set_string(value
, data
->scale
);
219 g_value_set_string(value
, data
->author
);
222 g_value_set_string(value
, data
->date
);
225 g_value_set_object(value
, data
->logo
);
227 case PROP_PROJECTION
:
228 g_value_set_object(value
, data
->projection
);
231 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
237 set_property(GObject
*object
,
238 guint prop_id
, const GValue
*value
, GParamSpec
*pspec
)
240 AdgTitleBlock
*title_block
= (AdgTitleBlock
*) object
;
244 set_title(title_block
, g_value_get_string(value
));
247 set_drawing(title_block
, g_value_get_string(value
));
250 set_size(title_block
, g_value_get_string(value
));
253 set_scale(title_block
, g_value_get_string(value
));
256 set_author(title_block
, g_value_get_string(value
));
259 set_date(title_block
, g_value_get_string(value
));
262 set_logo(title_block
, g_value_get_object(value
));
264 case PROP_PROJECTION
:
265 set_projection(title_block
, g_value_get_object(value
));
268 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
275 * adg_title_block_new:
277 * Creates a new empty title block entity. The #AdgEntity:local-method
278 * property is set by default to #ADG_MIX_DISABLED, that is the
279 * title block is not subject to any local transformations.
281 * Returns: the newly created title block entity
284 adg_title_block_new(void)
286 return g_object_new(ADG_TYPE_TITLE_BLOCK
,
287 "local-method", ADG_MIX_DISABLED
, NULL
);
291 * adg_title_block_set_title:
292 * @title_block: an #AdgTitleBlock entity
293 * @title: the new title
295 * Sets a new title on the title block.
298 adg_title_block_set_title(AdgTitleBlock
*title_block
, const gchar
*title
)
300 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block
));
302 if (set_title(title_block
, title
))
303 g_object_notify((GObject
*) title_block
, "title");
307 * adg_title_block_get_title:
308 * @title_block: an #AdgTitleBlock entity
310 * Gets the descriptive title associated to this title block.
311 * The returned string is owned by @title_block and should not
312 * be modifed or freed.
314 * Returns: the title or %NULL on no title or errors
317 adg_title_block_get_title(AdgTitleBlock
*title_block
)
319 AdgTitleBlockPrivate
*data
;
321 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block
), NULL
);
323 data
= title_block
->data
;
329 * adg_title_block_set_drawing:
330 * @title_block: an #AdgTitleBlock entity
331 * @drawing: the new drawing name
333 * Sets a new drawing name on the title block.
336 adg_title_block_set_drawing(AdgTitleBlock
*title_block
, const gchar
*drawing
)
338 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block
));
340 if (set_drawing(title_block
, drawing
))
341 g_object_notify((GObject
*) title_block
, "drawing");
345 * adg_title_block_get_drawing:
346 * @title_block: an #AdgTitleBlock entity
348 * Gets the drawing name, commonly used to specify the file name.
349 * The returned string is owned by @title_block and should not
350 * be modifed or freed.
352 * Returns: the drawing name or %NULL on no name or errors
355 adg_title_block_get_drawing(AdgTitleBlock
*title_block
)
357 AdgTitleBlockPrivate
*data
;
359 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block
), NULL
);
361 data
= title_block
->data
;
363 return data
->drawing
;
367 * adg_title_block_set_size:
368 * @title_block: an #AdgTitleBlock entity
369 * @size: the new size
371 * Sets a new size on the title block.
374 adg_title_block_set_size(AdgTitleBlock
*title_block
, const gchar
*size
)
376 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block
));
378 if (set_size(title_block
, size
))
379 g_object_notify((GObject
*) title_block
, "size");
383 * adg_title_block_get_size:
384 * @title_block: an #AdgTitleBlock entity
386 * Gets the media size (a descriptive name) where this drawing will
387 * be printed. Usually contains something like "A4" or "Letter".
388 * The returned string is owned by @title_block and should not
389 * be modifed or freed.
391 * Returns: the size or %NULL on no size or errors
394 adg_title_block_get_size(AdgTitleBlock
*title_block
)
396 AdgTitleBlockPrivate
*data
;
398 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block
), NULL
);
400 data
= title_block
->data
;
406 * adg_title_block_set_scale:
407 * @title_block: an #AdgTitleBlock entity
408 * @scale: the new scale
410 * Sets a new scale on the title block.
413 adg_title_block_set_scale(AdgTitleBlock
*title_block
, const gchar
*scale
)
415 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block
));
417 if (set_scale(title_block
, scale
))
418 g_object_notify((GObject
*) title_block
, "scale");
422 * adg_title_block_get_scale:
423 * @title_block: an #AdgTitleBlock entity
425 * Gets the scale descriptive name of the drawing.
427 * Returns: the scale text or %NULL on no scale or errors
430 adg_title_block_get_scale(AdgTitleBlock
*title_block
)
432 AdgTitleBlockPrivate
*data
;
434 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block
), NULL
);
436 data
= title_block
->data
;
442 * adg_title_block_set_author:
443 * @title_block: an #AdgTitleBlock entity
444 * @author: the new author
446 * Sets a new author on the title block.
449 adg_title_block_set_author(AdgTitleBlock
*title_block
, const gchar
*author
)
451 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block
));
453 if (set_author(title_block
, author
))
454 g_object_notify((GObject
*) title_block
, "author");
458 * adg_title_block_get_author:
459 * @title_block: an #AdgTitleBlock entity
461 * Gets the author's name of the drawing.
463 * Returns: the author or %NULL on no author or errors
466 adg_title_block_get_author(AdgTitleBlock
*title_block
)
468 AdgTitleBlockPrivate
*data
;
470 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block
), NULL
);
472 data
= title_block
->data
;
478 * adg_title_block_set_date:
479 * @title_block: an #AdgTitleBlock entity
480 * @date: the new date
482 * Sets a new date on the title block. By default the date is set
483 * to %NULL (so no date will be rendered) but setting it to an
484 * empty string (that is, %"") will implicitely set the date to
485 * today, by using the preferred representation for the current
486 * local. This will give a result roughly equivalent to:
489 * strftime(buffer, sizeof(buffer), "%x", now);
493 adg_title_block_set_date(AdgTitleBlock
*title_block
, const gchar
*date
)
495 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block
));
497 if (set_date(title_block
, date
))
498 g_object_notify((GObject
*) title_block
, "date");
502 * adg_title_block_get_date:
503 * @title_block: an #AdgTitleBlock entity
505 * Gets the date of the rendering set on @title_block.
507 * Returns: the date or %NULL on no date or errors
510 adg_title_block_get_date(AdgTitleBlock
*title_block
)
512 AdgTitleBlockPrivate
*data
;
514 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block
), NULL
);
516 data
= title_block
->data
;
522 * adg_title_block_set_logo:
523 * @title_block: an #AdgTitleBlock entity
524 * @logo: the new logo
526 * Sets a new logo on the title block. This function will add
527 * a reference to @logo, removing the eventual reference held
528 * to the old logo, hence possibly destroying the old endity.
530 * The space reserved for the logo is 56x56, so try to keep the
531 * new logo near this size or scale it accordingly.
534 adg_title_block_set_logo(AdgTitleBlock
*title_block
, AdgEntity
*logo
)
536 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block
));
538 if (set_logo(title_block
, logo
))
539 g_object_notify((GObject
*) title_block
, "logo");
543 * adg_title_block_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_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_projection:
566 * @title_block: an #AdgTitleBlock entity
567 * @projection: the new projection
569 * Sets a new projection symbol on the title block. This function
570 * will add a reference to @projection, removing the eventual
571 * reference held to the old symbol, hence possibly destroying
574 * The space reserved for the projection is 56x56, so try to keep the
575 * new projection near this size or scale it accordingly.
578 adg_title_block_set_projection(AdgTitleBlock
*title_block
,
579 AdgEntity
*projection
)
581 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block
));
583 if (set_projection(title_block
, projection
))
584 g_object_notify((GObject
*) title_block
, "projection");
588 * adg_title_block_projection:
589 * @title_block: an #AdgTitleBlock entity
591 * Gets the projection bound to this title block.
592 * The returned object is owned by @title_block and should not
593 * be unreferenced although can be freely modified.
595 * Returns: the projection or %NULL on no projection or errors
598 adg_title_block_projection(AdgTitleBlock
*title_block
)
600 AdgTitleBlockPrivate
*data
;
602 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block
), NULL
);
604 data
= title_block
->data
;
606 return data
->projection
;
611 get_table(AdgTitleBlock
*title_block
)
613 AdgTable
*table
= (AdgTable
*) title_block
;
615 if (adg_table_get_n_rows(table
) == 0) {
620 row
= adg_table_row_new(table
);
622 cell
= adg_table_cell_new(row
, 62);
624 cell
= adg_table_cell_new(row
, 200);
625 adg_table_cell_set_name(cell
, "title");
626 adg_table_cell_set_text_title(cell
, _("TITLE"));
627 adg_table_cell_switch_frame(cell
, TRUE
);
630 row
= adg_table_row_new(table
);
632 cell
= adg_table_cell_new(row
, 62);
633 adg_table_cell_set_name(cell
, "logo");
635 cell
= adg_table_cell_new(row
, 40);
636 adg_table_cell_set_name(cell
, "size");
637 adg_table_cell_set_text_title(cell
, _("SIZE"));
638 adg_table_cell_switch_frame(cell
, TRUE
);
640 cell
= adg_table_cell_new(row
, 60);
641 adg_table_cell_set_name(cell
, "scale");
642 adg_table_cell_set_text_title(cell
, _("SCALE"));
643 adg_table_cell_switch_frame(cell
, TRUE
);
645 cell
= adg_table_cell_new(row
, 100);
646 adg_table_cell_set_name(cell
, "drawing");
647 adg_table_cell_set_text_title(cell
, _("DRAWING"));
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
, "projection");
655 adg_table_cell_switch_frame(cell
, TRUE
);
657 cell
= adg_table_cell_new(row
, 100);
658 adg_table_cell_set_name(cell
, "author");
659 adg_table_cell_set_text_title(cell
, _("AUTHOR"));
660 adg_table_cell_switch_frame(cell
, TRUE
);
662 cell
= adg_table_cell_new(row
, 100);
663 adg_table_cell_set_name(cell
, "date");
664 adg_table_cell_set_text_title(cell
, _("DATE"));
665 adg_table_cell_switch_frame(cell
, TRUE
);
672 set_title(AdgTitleBlock
*title_block
, const gchar
*title
)
674 AdgTitleBlockPrivate
*data
;
678 data
= title_block
->data
;
680 if (adg_strcmp(title
, data
->title
) == 0)
684 data
->title
= g_strdup(title
);
686 table
= get_table(title_block
);
687 cell
= adg_table_cell(table
, "title");
688 adg_table_cell_set_text_value(cell
, data
->title
);
693 set_drawing(AdgTitleBlock
*title_block
, const gchar
*drawing
)
695 AdgTitleBlockPrivate
*data
;
699 data
= title_block
->data
;
701 if (adg_strcmp(drawing
, data
->drawing
) == 0)
704 g_free(data
->drawing
);
705 data
->drawing
= g_strdup(drawing
);
707 table
= get_table(title_block
);
708 cell
= adg_table_cell(table
, "drawing");
709 adg_table_cell_set_text_value(cell
, data
->drawing
);
714 set_size(AdgTitleBlock
*title_block
, const gchar
*size
)
716 AdgTitleBlockPrivate
*data
;
720 data
= title_block
->data
;
722 if (adg_strcmp(size
, data
->size
) == 0)
726 data
->size
= g_strdup(size
);
728 table
= get_table(title_block
);
729 cell
= adg_table_cell(table
, "size");
730 adg_table_cell_set_text_value(cell
, data
->size
);
735 set_scale(AdgTitleBlock
*title_block
, const gchar
*scale
)
737 AdgTitleBlockPrivate
*data
;
741 data
= title_block
->data
;
743 if (adg_strcmp(scale
, data
->scale
) == 0)
747 data
->scale
= g_strdup(scale
);
749 table
= get_table(title_block
);
750 cell
= adg_table_cell(table
, "scale");
751 adg_table_cell_set_text_value(cell
, data
->scale
);
756 set_author(AdgTitleBlock
*title_block
, const gchar
*author
)
758 AdgTitleBlockPrivate
*data
;
762 data
= title_block
->data
;
764 if (adg_strcmp(author
, data
->author
) == 0)
767 g_free(data
->author
);
768 data
->author
= g_strdup(author
);
770 table
= get_table(title_block
);
771 cell
= adg_table_cell(table
, "author");
772 adg_table_cell_set_text_value(cell
, data
->author
);
777 set_date(AdgTitleBlock
*title_block
, const gchar
*date
)
779 AdgTitleBlockPrivate
*data
;
783 data
= title_block
->data
;
785 if (adg_strcmp(date
, data
->date
) == 0)
790 if (date
!= NULL
&& date
[0] == '\0') {
791 /* The date must be automatically updated */
793 char buffer
[100] = { 0 };
795 gdate
= g_date_new();
796 g_date_set_time_t(gdate
, time (NULL
));
797 g_date_strftime(buffer
, sizeof(buffer
), "%x", gdate
);
800 data
->date
= g_strdup(buffer
);
802 data
->date
= g_strdup(date
);
805 table
= get_table(title_block
);
806 cell
= adg_table_cell(table
, "date");
807 adg_table_cell_set_text_value(cell
, data
->date
);
812 set_logo(AdgTitleBlock
*title_block
, AdgEntity
*logo
)
814 AdgTitleBlockPrivate
*data
;
819 data
= title_block
->data
;
821 if (logo
== data
->logo
)
830 table
= get_table(title_block
);
831 cell
= adg_table_cell(table
, "logo");
832 adg_table_cell_set_value(cell
, data
->logo
);
833 adg_table_cell_set_value_pos(cell
, &from
, &to
);
839 set_projection(AdgTitleBlock
*title_block
, AdgEntity
*projection
)
841 AdgTitleBlockPrivate
*data
;
846 data
= title_block
->data
;
848 if (projection
== data
->projection
)
851 data
->projection
= projection
;
855 table
= get_table(title_block
);
856 cell
= adg_table_cell(table
, "projection");
857 adg_table_cell_set_value(cell
, data
->projection
);
858 adg_table_cell_set_value_pos(cell
, ¢er
, ¢er
);