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
!= NULL
)
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_get_title:
292 * @title_block: an #AdgTitleBlock entity
294 * Gets the descriptive title associated to this title block.
295 * The returned string is owned by @title_block and should not
296 * be modifed or freed.
298 * Returns: the title or %NULL on no title or errors
301 adg_title_block_get_title(AdgTitleBlock
*title_block
)
303 AdgTitleBlockPrivate
*data
;
305 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block
), NULL
);
307 data
= title_block
->data
;
313 * adg_title_block_set_title:
314 * @title_block: an #AdgTitleBlock entity
315 * @title: the new title
317 * Sets a new title on the title block.
320 adg_title_block_set_title(AdgTitleBlock
*title_block
, const gchar
*title
)
322 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block
));
324 if (set_title(title_block
, title
))
325 g_object_notify((GObject
*) title_block
, "title");
329 * adg_title_block_get_drawing:
330 * @title_block: an #AdgTitleBlock entity
332 * Gets the drawing name, commonly used to specify the file name.
333 * The returned string is owned by @title_block and should not
334 * be modifed or freed.
336 * Returns: the drawing name or %NULL on no name or errors
339 adg_title_block_get_drawing(AdgTitleBlock
*title_block
)
341 AdgTitleBlockPrivate
*data
;
343 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block
), NULL
);
345 data
= title_block
->data
;
347 return data
->drawing
;
351 * adg_title_block_set_drawing:
352 * @title_block: an #AdgTitleBlock entity
353 * @drawing: the new drawing name
355 * Sets a new drawing name on the title block.
358 adg_title_block_set_drawing(AdgTitleBlock
*title_block
, const gchar
*drawing
)
360 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block
));
362 if (set_drawing(title_block
, drawing
))
363 g_object_notify((GObject
*) title_block
, "drawing");
367 * adg_title_block_get_size:
368 * @title_block: an #AdgTitleBlock entity
370 * Gets the media size (a descriptive name) where this drawing will
371 * be printed. Usually contains something like "A4" or "Letter".
372 * The returned string is owned by @title_block and should not
373 * be modifed or freed.
375 * Returns: the size or %NULL on no size or errors
378 adg_title_block_get_size(AdgTitleBlock
*title_block
)
380 AdgTitleBlockPrivate
*data
;
382 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block
), NULL
);
384 data
= title_block
->data
;
390 * adg_title_block_set_size:
391 * @title_block: an #AdgTitleBlock entity
392 * @size: the new size
394 * Sets a new size on the title block.
397 adg_title_block_set_size(AdgTitleBlock
*title_block
, const gchar
*size
)
399 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block
));
401 if (set_size(title_block
, size
))
402 g_object_notify((GObject
*) title_block
, "size");
406 * adg_title_block_get_scale:
407 * @title_block: an #AdgTitleBlock entity
409 * Gets the scale descriptive name of the drawing.
411 * Returns: the scale text or %NULL on no scale or errors
414 adg_title_block_get_scale(AdgTitleBlock
*title_block
)
416 AdgTitleBlockPrivate
*data
;
418 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block
), NULL
);
420 data
= title_block
->data
;
426 * adg_title_block_set_scale:
427 * @title_block: an #AdgTitleBlock entity
428 * @scale: the new scale
430 * Sets a new scale on the title block.
433 adg_title_block_set_scale(AdgTitleBlock
*title_block
, const gchar
*scale
)
435 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block
));
437 if (set_scale(title_block
, scale
))
438 g_object_notify((GObject
*) title_block
, "scale");
442 * adg_title_block_get_author:
443 * @title_block: an #AdgTitleBlock entity
445 * Gets the author's name of the drawing.
447 * Returns: the author or %NULL on no author or errors
450 adg_title_block_get_author(AdgTitleBlock
*title_block
)
452 AdgTitleBlockPrivate
*data
;
454 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block
), NULL
);
456 data
= title_block
->data
;
462 * adg_title_block_set_author:
463 * @title_block: an #AdgTitleBlock entity
464 * @author: the new author
466 * Sets a new author on the title block.
469 adg_title_block_set_author(AdgTitleBlock
*title_block
, const gchar
*author
)
471 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block
));
473 if (set_author(title_block
, author
))
474 g_object_notify((GObject
*) title_block
, "author");
478 * adg_title_block_get_date:
479 * @title_block: an #AdgTitleBlock entity
481 * Gets the date of the rendering set on @title_block.
483 * Returns: the date or %NULL on no date or errors
486 adg_title_block_get_date(AdgTitleBlock
*title_block
)
488 AdgTitleBlockPrivate
*data
;
490 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block
), NULL
);
492 data
= title_block
->data
;
498 * adg_title_block_set_date:
499 * @title_block: an #AdgTitleBlock entity
500 * @date: the new date
502 * Sets a new date on the title block. By default the date is set
503 * to %NULL (so no date will be rendered) but setting it to an
504 * empty string (that is, %"") will implicitely set the date to
505 * today, by using the preferred representation for the current
506 * local. This will give a result roughly equivalent to:
509 * strftime(buffer, sizeof(buffer), "%x", now);
513 adg_title_block_set_date(AdgTitleBlock
*title_block
, const gchar
*date
)
515 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block
));
517 if (set_date(title_block
, date
))
518 g_object_notify((GObject
*) title_block
, "date");
522 * adg_title_block_get_logo:
523 * @title_block: an #AdgTitleBlock entity
525 * Gets the logo bound to this title block.
526 * The returned object is owned by @title_block and should not
527 * be unreferenced although can be freely modified.
529 * Returns: the logo or %NULL on no logo or errors
532 adg_title_block_get_logo(AdgTitleBlock
*title_block
)
534 AdgTitleBlockPrivate
*data
;
536 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block
), NULL
);
538 data
= title_block
->data
;
544 * adg_title_block_set_logo:
545 * @title_block: an #AdgTitleBlock entity
546 * @logo: the new logo
548 * Sets a new logo on the title block. This function will add
549 * a reference to @logo, removing the eventual reference held
550 * to the old logo, hence possibly destroying the old endity.
552 * The space reserved for the logo is 56x56, so try to keep the
553 * new logo near this size or scale it accordingly.
556 adg_title_block_set_logo(AdgTitleBlock
*title_block
, AdgEntity
*logo
)
558 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block
));
560 if (set_logo(title_block
, logo
))
561 g_object_notify((GObject
*) title_block
, "logo");
565 * adg_title_block_get_projection:
566 * @title_block: an #AdgTitleBlock entity
568 * Gets the projection bound to this title block.
569 * The returned object is owned by @title_block and should not
570 * be unreferenced although can be freely modified.
572 * Returns: the projection or %NULL on no projection or errors
575 adg_title_block_get_projection(AdgTitleBlock
*title_block
)
577 AdgTitleBlockPrivate
*data
;
579 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block
), NULL
);
581 data
= title_block
->data
;
583 return data
->projection
;
587 * adg_title_block_set_projection:
588 * @title_block: an #AdgTitleBlock entity
589 * @projection: the new projection
591 * Sets a new projection symbol on the title block. This function
592 * will add a reference to @projection, removing the eventual
593 * reference held to the old symbol, hence possibly destroying
596 * The space reserved for the projection is 56x56, so try to keep the
597 * new projection near this size or scale it accordingly.
600 adg_title_block_set_projection(AdgTitleBlock
*title_block
,
601 AdgEntity
*projection
)
603 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block
));
605 if (set_projection(title_block
, projection
))
606 g_object_notify((GObject
*) title_block
, "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_get_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_get_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_get_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_get_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_get_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_get_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_get_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_get_cell(table
, "projection");
857 adg_table_cell_set_value(cell
, data
->projection
);
858 adg_table_cell_set_value_pos(cell
, ¢er
, ¢er
);