1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007,2008,2009,2010,2011 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-internal.h"
43 #include "adg-table.h"
45 #include "adg-title-block.h"
46 #include "adg-title-block-private.h"
49 #define _ADG_OLD_OBJECT_CLASS ((GObjectClass *) adg_title_block_parent_class)
52 G_DEFINE_TYPE(AdgTitleBlock
, adg_title_block
, ADG_TYPE_TABLE
);
67 static void _adg_finalize (GObject
*object
);
68 static void _adg_get_property (GObject
*object
,
72 static void _adg_set_property (GObject
*object
,
76 static AdgTable
* _adg_get_table (AdgTitleBlock
*title_block
);
80 adg_title_block_class_init(AdgTitleBlockClass
*klass
)
82 GObjectClass
*gobject_class
;
85 gobject_class
= (GObjectClass
*) klass
;
87 g_type_class_add_private(klass
, sizeof(AdgTitleBlockPrivate
));
89 gobject_class
->finalize
= _adg_finalize
;
90 gobject_class
->set_property
= _adg_set_property
;
91 gobject_class
->get_property
= _adg_get_property
;
93 param
= g_param_spec_string("title",
95 P_("A descriptive title of the drawing"),
98 g_object_class_install_property(gobject_class
, PROP_TITLE
, param
);
100 param
= g_param_spec_string("drawing",
102 P_("The name of the drawing: the ADG canvas does not make any assumtpion on this text string"),
105 g_object_class_install_property(gobject_class
, PROP_DRAWING
, param
);
107 param
= g_param_spec_string("size",
109 P_("The media size to be used to print the drawing, usually something like \"A3\" or \"Letter\""),
112 g_object_class_install_property(gobject_class
, PROP_SIZE
, param
);
114 param
= g_param_spec_string("scale",
116 P_("The scale of the drawing, if it makes sense"),
119 g_object_class_install_property(gobject_class
, PROP_SCALE
, param
);
121 param
= g_param_spec_string("author",
123 P_("Name and last name of the author of the drawing"),
126 g_object_class_install_property(gobject_class
, PROP_AUTHOR
, param
);
128 param
= g_param_spec_string("date",
130 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"),
133 g_object_class_install_property(gobject_class
, PROP_DATE
, param
);
135 param
= g_param_spec_object("logo",
137 P_("An entity to be displayed in the title block as the logo of the owner: the containing cell has a 1:1 ratio"),
140 g_object_class_install_property(gobject_class
, PROP_LOGO
, param
);
142 param
= g_param_spec_object("projection",
143 P_("Projection Scheme"),
144 P_("The entity usually reserved to identify the projection scheme adopted by this drawing"),
147 g_object_class_install_property(gobject_class
, PROP_PROJECTION
, param
);
151 adg_title_block_init(AdgTitleBlock
*title_block
)
153 AdgTitleBlockPrivate
*data
= G_TYPE_INSTANCE_GET_PRIVATE(title_block
,
154 ADG_TYPE_TITLE_BLOCK
,
155 AdgTitleBlockPrivate
);
158 data
->drawing
= NULL
;
163 data
->projection
= NULL
;
165 title_block
->data
= data
;
169 _adg_finalize(GObject
*object
)
171 AdgTitleBlockPrivate
*data
= ((AdgTitleBlock
*) object
)->data
;
174 g_free(data
->drawing
);
177 g_free(data
->author
);
180 if (_ADG_OLD_OBJECT_CLASS
->finalize
)
181 _ADG_OLD_OBJECT_CLASS
->finalize(object
);
185 _adg_get_property(GObject
*object
, guint prop_id
,
186 GValue
*value
, GParamSpec
*pspec
)
188 AdgTitleBlockPrivate
*data
= ((AdgTitleBlock
*) object
)->data
;
192 g_value_set_string(value
, data
->title
);
195 g_value_set_string(value
, data
->drawing
);
198 g_value_set_string(value
, data
->size
);
201 g_value_set_string(value
, data
->scale
);
204 g_value_set_string(value
, data
->author
);
207 g_value_set_string(value
, data
->date
);
210 g_value_set_object(value
, data
->logo
);
212 case PROP_PROJECTION
:
213 g_value_set_object(value
, data
->projection
);
216 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
222 _adg_set_property(GObject
*object
, guint prop_id
,
223 const GValue
*value
, GParamSpec
*pspec
)
225 AdgTitleBlock
*title_block
;
226 AdgTitleBlockPrivate
*data
;
230 title_block
= (AdgTitleBlock
*) object
;
231 data
= title_block
->data
;
232 table
= _adg_get_table(title_block
);
237 data
->title
= g_value_dup_string(value
);
238 cell
= adg_table_cell(table
, "title");
239 adg_table_cell_set_text_value(cell
, data
->title
);
242 g_free(data
->drawing
);
243 data
->drawing
= g_value_dup_string(value
);
244 cell
= adg_table_cell(table
, "drawing");
245 adg_table_cell_set_text_value(cell
, data
->drawing
);
249 data
->size
= g_value_dup_string(value
);
250 cell
= adg_table_cell(table
, "size");
251 adg_table_cell_set_text_value(cell
, data
->size
);
255 data
->scale
= g_value_dup_string(value
);
256 cell
= adg_table_cell(table
, "scale");
257 adg_table_cell_set_text_value(cell
, data
->scale
);
260 g_free(data
->author
);
261 data
->author
= g_value_dup_string(value
);
262 cell
= adg_table_cell(table
, "author");
263 adg_table_cell_set_text_value(cell
, data
->author
);
267 if (g_value_get_string(value
) == NULL
) {
268 /* NULL means the date must be automatically updated */
270 char buffer
[100] = { 0 };
272 gdate
= g_date_new();
273 g_date_set_time_t(gdate
, time (NULL
));
274 g_date_strftime(buffer
, sizeof(buffer
), "%x", gdate
);
277 data
->date
= g_strdup(buffer
);
279 data
->date
= g_value_dup_string(value
);
281 cell
= adg_table_cell(table
, "date");
282 adg_table_cell_set_text_value(cell
, data
->date
);
285 data
->logo
= g_value_get_object(value
);
286 cell
= adg_table_cell(table
, "logo");
287 adg_table_cell_set_value(cell
, data
->logo
);
288 adg_table_cell_set_value_pos_explicit(cell
, 0.5, 1, 0.5, 0.5);
290 case PROP_PROJECTION
:
291 data
->projection
= g_value_get_object(value
);
292 cell
= adg_table_cell(table
, "projection");
293 adg_table_cell_set_value(cell
, data
->projection
);
294 adg_table_cell_set_value_pos_explicit(cell
, 0.5, 0.5, 0.5, 0.5);
297 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
304 * adg_title_block_new:
306 * Creates a new empty title block entity. The #AdgEntity:local-method
307 * property is set by default to #ADG_MIX_DISABLED, that is the
308 * title block is not subject to any local transformations.
310 * Returns: the newly created title block entity
313 adg_title_block_new(void)
315 return g_object_new(ADG_TYPE_TITLE_BLOCK
,
316 "local-method", ADG_MIX_DISABLED
, NULL
);
320 * adg_title_block_set_title:
321 * @title_block: an #AdgTitleBlock entity
322 * @title: the new title
324 * Sets a new title on the title block.
327 adg_title_block_set_title(AdgTitleBlock
*title_block
, const gchar
*title
)
329 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block
));
330 g_object_set(title_block
, "title", title
, NULL
);
334 * adg_title_block_get_title:
335 * @title_block: an #AdgTitleBlock entity
337 * Gets the descriptive title associated to this title block.
338 * The returned string is owned by @title_block and should not
339 * be modifed or freed.
341 * Returns: the title or %NULL on no title or errors
344 adg_title_block_get_title(AdgTitleBlock
*title_block
)
346 AdgTitleBlockPrivate
*data
;
348 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block
), NULL
);
350 data
= title_block
->data
;
356 * adg_title_block_set_drawing:
357 * @title_block: an #AdgTitleBlock entity
358 * @drawing: the new drawing name
360 * Sets a new drawing name on the title block.
363 adg_title_block_set_drawing(AdgTitleBlock
*title_block
, const gchar
*drawing
)
365 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block
));
366 g_object_set(title_block
, "drawing", drawing
, NULL
);
370 * adg_title_block_get_drawing:
371 * @title_block: an #AdgTitleBlock entity
373 * Gets the drawing name, commonly used to specify the file name.
374 * The returned string is owned by @title_block and should not
375 * be modifed or freed.
377 * Returns: the drawing name or %NULL on no name or errors
380 adg_title_block_get_drawing(AdgTitleBlock
*title_block
)
382 AdgTitleBlockPrivate
*data
;
384 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block
), NULL
);
386 data
= title_block
->data
;
388 return data
->drawing
;
392 * adg_title_block_set_size:
393 * @title_block: an #AdgTitleBlock entity
394 * @size: the new size
396 * Sets a new size on the title block.
399 adg_title_block_set_size(AdgTitleBlock
*title_block
, const gchar
*size
)
401 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block
));
402 g_object_set(title_block
, "size", size
, NULL
);
406 * adg_title_block_get_size:
407 * @title_block: an #AdgTitleBlock entity
409 * Gets the media size (a descriptive name) where this drawing will
410 * be printed. Usually contains something like "A4" or "Letter".
411 * The returned string is owned by @title_block and should not
412 * be modifed or freed.
414 * Returns: the size or %NULL on no size or errors
417 adg_title_block_get_size(AdgTitleBlock
*title_block
)
419 AdgTitleBlockPrivate
*data
;
421 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block
), NULL
);
423 data
= title_block
->data
;
429 * adg_title_block_set_scale:
430 * @title_block: an #AdgTitleBlock entity
431 * @scale: the new scale
433 * Sets a new scale on the title block.
436 adg_title_block_set_scale(AdgTitleBlock
*title_block
, const gchar
*scale
)
438 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block
));
439 g_object_set(title_block
, "scale", scale
, NULL
);
443 * adg_title_block_get_scale:
444 * @title_block: an #AdgTitleBlock entity
446 * Gets the scale descriptive name of the drawing.
448 * Returns: the scale text or %NULL on no scale or errors
451 adg_title_block_get_scale(AdgTitleBlock
*title_block
)
453 AdgTitleBlockPrivate
*data
;
455 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block
), NULL
);
457 data
= title_block
->data
;
463 * adg_title_block_set_author:
464 * @title_block: an #AdgTitleBlock entity
465 * @author: the new author
467 * Sets a new author on the title block.
470 adg_title_block_set_author(AdgTitleBlock
*title_block
, const gchar
*author
)
472 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block
));
473 g_object_set(title_block
, "author", author
, NULL
);
477 * adg_title_block_get_author:
478 * @title_block: an #AdgTitleBlock entity
480 * Gets the author's name of the drawing.
482 * Returns: the author or %NULL on no author or errors
485 adg_title_block_get_author(AdgTitleBlock
*title_block
)
487 AdgTitleBlockPrivate
*data
;
489 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block
), NULL
);
491 data
= title_block
->data
;
497 * adg_title_block_set_date:
498 * @title_block: an #AdgTitleBlock entity
499 * @date: the new date
501 * Sets a new date on the title block. By default the date is
502 * set to %NULL and it will be implicitely rendered using the
503 * preferred representation for the current local of the actual
504 * date. This is roughly equivalent to:
507 * strftime(buffer, sizeof(buffer), "%x", now);
508 * adg_title_block_set_date(title_block, buffer);
511 * To not render any value, use an empty string as @date.
514 adg_title_block_set_date(AdgTitleBlock
*title_block
, const gchar
*date
)
516 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block
));
517 g_object_set(title_block
, "date", date
, NULL
);
521 * adg_title_block_get_date:
522 * @title_block: an #AdgTitleBlock entity
524 * Gets the date of the rendering set on @title_block.
526 * Returns: the date or %NULL on no date or errors
529 adg_title_block_get_date(AdgTitleBlock
*title_block
)
531 AdgTitleBlockPrivate
*data
;
533 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block
), NULL
);
535 data
= title_block
->data
;
541 * adg_title_block_set_logo:
542 * @title_block: an #AdgTitleBlock entity
543 * @logo: the new logo
545 * Sets a new logo on the title block. This function will add
546 * a reference to @logo, removing the eventual reference held
547 * to the old logo, hence possibly destroying the old endity.
549 * The space reserved for the logo is 56x56, so try to keep the
550 * new logo near this size or scale it accordingly.
553 adg_title_block_set_logo(AdgTitleBlock
*title_block
, AdgEntity
*logo
)
555 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block
));
556 g_object_set(title_block
, "logo", logo
, NULL
);
560 * adg_title_block_logo:
561 * @title_block: an #AdgTitleBlock entity
563 * Gets the logo bound to this title block.
564 * The returned object is owned by @title_block and should not
565 * be unreferenced although can be freely modified.
567 * Returns: the logo or %NULL on no logo or errors
570 adg_title_block_logo(AdgTitleBlock
*title_block
)
572 AdgTitleBlockPrivate
*data
;
574 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block
), NULL
);
576 data
= title_block
->data
;
582 * adg_title_block_set_projection:
583 * @title_block: an #AdgTitleBlock entity
584 * @projection: the new projection
586 * Sets a new projection symbol on the title block. This function
587 * will add a reference to @projection, removing the eventual
588 * reference held to the old symbol, hence possibly destroying
591 * The space reserved for the projection is 56x56, so try to keep the
592 * new projection near this size or scale it accordingly.
595 adg_title_block_set_projection(AdgTitleBlock
*title_block
,
596 AdgEntity
*projection
)
598 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block
));
599 g_object_set(title_block
, "projection", projection
, NULL
);
603 * adg_title_block_projection:
604 * @title_block: an #AdgTitleBlock entity
606 * Gets the projection bound to this title block.
607 * The returned object is owned by @title_block and should not
608 * be unreferenced although can be freely modified.
610 * Returns: the projection or %NULL on no projection or errors
613 adg_title_block_projection(AdgTitleBlock
*title_block
)
615 AdgTitleBlockPrivate
*data
;
617 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block
), NULL
);
619 data
= title_block
->data
;
621 return data
->projection
;
626 _adg_get_table(AdgTitleBlock
*title_block
)
628 AdgTable
*table
= (AdgTable
*) title_block
;
630 if (adg_table_get_n_rows(table
) == 0) {
635 row
= adg_table_row_new(table
);
637 cell
= adg_table_cell_new(row
, 62);
639 cell
= adg_table_cell_new(row
, 200);
640 adg_table_cell_set_name(cell
, "title");
641 adg_table_cell_set_text_title(cell
, _("TITLE"));
642 adg_table_cell_switch_frame(cell
, TRUE
);
645 row
= adg_table_row_new(table
);
647 cell
= adg_table_cell_new(row
, 62);
648 adg_table_cell_set_name(cell
, "logo");
650 cell
= adg_table_cell_new(row
, 40);
651 adg_table_cell_set_name(cell
, "size");
652 adg_table_cell_set_text_title(cell
, _("SIZE"));
653 adg_table_cell_switch_frame(cell
, TRUE
);
655 cell
= adg_table_cell_new(row
, 60);
656 adg_table_cell_set_name(cell
, "scale");
657 adg_table_cell_set_text_title(cell
, _("SCALE"));
658 adg_table_cell_switch_frame(cell
, TRUE
);
660 cell
= adg_table_cell_new(row
, 100);
661 adg_table_cell_set_name(cell
, "drawing");
662 adg_table_cell_set_text_title(cell
, _("DRAWING"));
663 adg_table_cell_switch_frame(cell
, TRUE
);
666 row
= adg_table_row_new(table
);
668 cell
= adg_table_cell_new(row
, 62);
669 adg_table_cell_set_name(cell
, "projection");
670 adg_table_cell_switch_frame(cell
, TRUE
);
672 cell
= adg_table_cell_new(row
, 100);
673 adg_table_cell_set_name(cell
, "author");
674 adg_table_cell_set_text_title(cell
, _("AUTHOR"));
675 adg_table_cell_switch_frame(cell
, TRUE
);
677 cell
= adg_table_cell_new(row
, 100);
678 adg_table_cell_set_name(cell
, "date");
679 adg_table_cell_set_text_title(cell
, _("DATE"));
680 adg_table_cell_switch_frame(cell
, TRUE
);