Updated copyright text/header in most source files.
[geda-gaf/peter-b.git] / libgeda / src / o_embed.c
blobcb3699dad943d626de09571a6453cc3c9f814579
1 /* gEDA - GPL Electronic Design Automation
2 * libgeda - gEDA's library
3 * Copyright (C) 1998-2010 Ales Hvezda
4 * Copyright (C) 1998-2010 gEDA Contributors (see ChangeLog for details)
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
21 /*! \file o_embed.c
22 * \brief functions to embed and unembed symbols
25 #include <config.h>
27 #include <stdio.h>
29 #include "libgeda_priv.h"
31 #ifdef HAVE_LIBDMALLOC
32 #include <dmalloc.h>
33 #endif
36 /*! \brief embed an object into a schematic
37 * \par Function Description
38 * This functions embeds an object \a o_current into a
39 * libgeda. Currently complex objects are just marked to
40 * be embedded later. Picture objects are embedded immediatly.
42 * \param toplevel The TOPLEVEL object
43 * \param o_current The OBJECT to embed
45 void o_embed(TOPLEVEL *toplevel, OBJECT *o_current)
48 /* check o_current is a complex and is not already embedded */
49 if (o_current->type == OBJ_COMPLEX &&
50 !o_complex_is_embedded (o_current))
53 /* set the embedded flag */
54 o_current->complex_embedded = TRUE;
56 s_log_message (_("Component [%s] has been embedded\n"),
57 o_current->complex_basename);
59 /* page content has been modified */
60 toplevel->page_current->CHANGED = 1;
63 /* If it's a picture and it's not embedded */
64 if ( (o_current->type == OBJ_PICTURE) &&
65 (o_current->picture->embedded == 0) ) {
66 o_picture_embed (toplevel, o_current);
68 /* page content has been modified */
69 toplevel->page_current->CHANGED = 1;
73 /*! \brief unembed an object from a schematic
74 * \par Function Description
75 * This functions unembeds an object \a o_current from a
76 * libgeda structure. Complex objects are just marked to
77 * be not embedded. Picture objects are unembeded immediatly.
79 * \param toplevel The TOPLEVEL object
80 * \param o_current The OBJECT to unembed
82 void o_unembed(TOPLEVEL *toplevel, OBJECT *o_current)
84 const CLibSymbol *sym;
86 /* check o_current is an embedded complex */
87 if (o_current->type == OBJ_COMPLEX &&
88 o_complex_is_embedded (o_current))
91 /* search for the symbol in the library */
92 sym = s_clib_get_symbol_by_name (o_current->complex_basename);
94 if (sym == NULL) {
95 /* symbol not found in the symbol library: signal an error */
96 s_log_message (_("Could not find component [%s], while trying to "
97 "unembed. Component is still embedded\n"),
98 o_current->complex_basename);
100 } else {
101 /* clear the embedded flag */
102 o_current->complex_embedded = FALSE;
104 s_log_message (_("Component [%s] has been successfully unembedded\n"),
105 o_current->complex_basename);
107 /* page content has been modified */
108 toplevel->page_current->CHANGED = 1;
113 /* If it's a picture and it's embedded */
114 if ( (o_current->type == OBJ_PICTURE) &&
115 (o_current->picture->embedded == 1) ) {
116 o_picture_unembed (toplevel, o_current);
118 /* page content has been modified */
119 toplevel->page_current->CHANGED = 1;